[22891] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5112 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 12 18:10:50 2003

Date: Thu, 12 Jun 2003 15:10:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 12 Jun 2003     Volume: 10 Number: 5112

Today's topics:
        Graph data structure (slash)
    Re: How to do a 'wrapper' on Windows? (Carlton Brown)
    Re: How to I arrange for a socket connection to time ou (John Brock)
    Re: How to make write()/format behave more like Text::W <No_4@dsl.pipex.com>
    Re: How to make write()/format behave more like Text::W <No_4@dsl.pipex.com>
    Re: Installing Perl 5.8 <daveuhring@yahoo.com>
    Re: Installing Perl 5.8 <massimiliano.adamoNOSPAM@renodemedici.it>
    Re: Installing Perl 5.8 <ddunham@redwood.taos.com>
    Re: Installing Perl 5.8 <tzz@lifelogs.com>
    Re: Installing Perl 5.8 <tzz@lifelogs.com>
        Multiple threads append data to the same file (Daniel Lou)
    Re: newbie: will a big array hurt performance? ctcgag@hotmail.com
        regex help <babernat@purdue.edu>
    Re: regex help <mbudash@sonic.net>
    Re: regex help <TruthXayer@yahoo.com>
    Re: regex help (Tad McClellan)
    Re: Sanitizing a regular expression <bernie@rev.net>
    Re: Sanitizing a regular expression <tzz@lifelogs.com>
    Re: Sanitizing a regular expression <usenet@expires082003.tinita.de>
    Re: Sanitizing a regular expression <bernie@rev.net>
        Search through Array and evaluate the two (Almir)
    Re: Search through Array and evaluate the two <jkeen@concentric.net>
    Re: Search through Array and evaluate the two <skuo@mtwhitney.nsc.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 12 Jun 2003 12:27:29 -0700
From: satishi@gwu.edu (slash)
Subject: Graph data structure
Message-Id: <30fe9f1e.0306121127.36b52b8@posting.google.com>

Hi,'
I desperately need some help with this problem.I have been playing
with the Graph and Graph::Base module for a day now with no success. I
would certainly appreciate any tips or suggestions you could give me.
Following is my input:

a       r
a       r
a       c
a       c
a       d
c       a
c       a
c       g
c       e
c       e
c       g
c       g
c       f
d       a
d       d
d       d
d       e
d       e
d       g
e       d
e       d
e       c
e       c
f       c
f       r
g       d
g       c
g       c
g       c
r       a
r       a
r       f
r       g


And, I am trying to produce a graph where the following rules are
being observed:

1. node cannot be in previous layers (parent or grandparent not
allowed)
2. no repeating nodes in the same branch

The output I want is the following where the columns represent the
layers:

a
      c   
            e
            f
            g
      d
            e
            g
      r
            f
            g

Any help would be greatly appreciated. Looking forward to a response.

Slash


------------------------------

Date: 12 Jun 2003 15:03:36 -0700
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: How to do a 'wrapper' on Windows?
Message-Id: <aa611a32.0306121403.6046299b@posting.google.com>

Ted Zlatanov <tzz@lifelogs.com> wrote in message news:<4nn0gnl4m7.fsf@lockgroove.bwh.harvard.edu>...
> I agree with Carlton's ideas, but he relies on a CR/LF being pressed.
> The user could be typing, backspacing, hitting TAB, etc.

Well yeah, but anybody who doesn't hit return at least every 15
minutes is probably sandbagging.  They don't need to hog a database
license while they're playing Monkey Lander or having a narcoleptic
attack or whatever.

In fact, if you're trapping characters with Term::Key and the user is
just sitting there typing characters without a CR/LF, you should
programmatically send the supervisor a mail alert that the user is
obviously clueless and should immediately be demoted to 3rd-alternate
stapler refiller.

http://www.miniclip.com/monkeylander.htm

:^)


------------------------------

Date: 12 Jun 2003 16:02:49 -0400
From: jbrock@panix.com (John Brock)
Subject: Re: How to I arrange for a socket connection to time out?
Message-Id: <bcam99$nrp$1@panix1.panix.com>

In article <XVMFa.27236$MM4.4946477@news0.telusplanet.net>,
BrianC <nospam@spamcop.com> wrote:
>
>"BrianC" <nospam@spamcop.com> wrote in message
>news:hMMFa.27201$MM4.4944200@news0.telusplanet.net...
>> > > I did this:
>> > >
>> > >$CLIENT_MAX_WAIT = 60;
>> > >my $time = time;
>> > >while (defined ($buf = <$sock>) )
>> > > {
>> > > $response .= $buf;
>> > > if( time - $time > $CLIENT_MAX_WAIT) { print "timed out\n"; last(); }
>> > > }
>> > >close $sock;

>> > What if $buf = <$sock> never returns?

>>  You are right. This works better on the client side:

> I have been wrong twice! This works best:
>
>$sock->timeout($CLIENT_MAX_WAIT );
>while (defined ($buf = <$sock>) ) { print $buf; }
>close $sock;

Actually I don't think this works either, although the problem is
more subtle.  The timeout implemented by the timeout() method of
IO::Socket only applies to the connect() and accept() methods (I
had to read the code for IO::Socket before I realized this), and
in any case you are accessing the socket filehandle directly via
the angle bracket operator instead of through a method (the
appropriate method would be getline() from the IO:Handle superclass),
so you've bypassed any possible IO::Socket processing anyway.  The
way I finally ended up doing this involved using both IO::Socket
to deal with the socket and the can_read() method of IO::Select to
implement the timeout.  It makes sense once you know what is going
on, but that took me a while.
-- 
John Brock
jbrock@panix.com



------------------------------

Date: Thu, 12 Jun 2003 20:55:29 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: How to make write()/format behave more like Text::Wrap?
Message-Id: <3ee8dab1$0$11383$cc9e4d1f@news.dial.pipex.com>

Gerard Lanois wrote:
> # If you omit the following statement, write()/format quits when it
> # sees the first \cM.

    Not that it solves your problem, but if you use \n instead of \cM\cJ 
it keeps going (but still ignores the newlines)




-- 
      -*-    Just because I've written it here doesn't    -*-
      -*-    mean that you should, or I do, believe it.   -*-



------------------------------

Date: Thu, 12 Jun 2003 22:11:53 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: How to make write()/format behave more like Text::Wrap?
Message-Id: <3ee8ec99$0$11383$cc9e4d1f@news.dial.pipex.com>

Gerard Lanois wrote:

> # If you omit the following statement, write()/format quits when it
> # sees the first \cM.  Not desireable; I want write()/format to 
> # process my entire string.
> $text =~ s/\cM\cJ/\cJ/g;

    This works (it's got \n rather than \cM\cJ, but if you really want 
to enforce that I'm sure you can adapt it...

#! /usr/bin/perl -w
use strict;

# I have some text that looks like this.
my $text = "Xxx xxxxxxxxx xxxx xxxx xxxxxx xxxxxxx xxx xx x ".
"xxxxxx.  Xxx xxxx xx xxxxxx xxxxxxxxx xxxx xxxx xxxx x xxxxx. ".
"Xxx xxxxxxx xxxx xxxx xxxx xxxxx xxx XXXXXXXXX_XXX_XXXX xxxxxxxxxx ".
"xxxxxxx, xxx xxx xxxxxxxxx xxxx XXXXXXX xx.\nXxx xxxx ".
"xxxx\nXxxxxxxx XX 1234567890, Xxxxxx XXXXX12345678";


my $f_text;
format =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$f_text
 .

foreach $f_text (split(/\n/, $text)) {
    write;
}

-- 
      -*-    Just because I've written it here doesn't    -*-
      -*-    mean that you should, or I do, believe it.   -*-



------------------------------

Date: Thu, 12 Jun 2003 10:19:46 -0500
From: Dave Uhring <daveuhring@yahoo.com>
Subject: Re: Installing Perl 5.8
Message-Id: <pan.2003.06.12.15.19.46.544041@yahoo.com>

On Thu, 12 Jun 2003 07:23:48 -0700, Philip Juels wrote:

> Hi all,
> 
> I'd like to install Perl 5.8.0 on our Fire 880 Solaris box, but I have
> a few concerns:
> 
> 1)  I understand its NOT a good idea to remove/replace the Perl
> version bundled with Solaris...okay that's fine, I'll just install the
> Sunfreeware package which puts it in /usr/local, but...
> 2)  How do I install CPAN modules to the newer Perl rather than the
> default old one?

The Solaris scripts which require perl use the full path to the required
version.

ln -s /usr/local/bin/perl /usr/bin/perl



------------------------------

Date: Thu, 12 Jun 2003 17:26:07 +0200
From: Massimiliano Adamo <massimiliano.adamoNOSPAM@renodemedici.it>
Subject: Re: Installing Perl 5.8
Message-Id: <bca620$gmfua$1@ID-125418.news.dfncis.de>

On Thu, 12 Jun 2003 16:23:48 +0200, Philip Juels wrote:


> 2)  How do I install CPAN modules to the newer Perl rather than the
> default old one?

Just reinstall them ;) I reinstalled and they run.

I installed the this afternoon.
untar file, go in directory and do the following -> 
make Makefile.PL
make
make install

(of course I have not both PERL, but just one)

Bye
--
Massimiliano.


------------------------------

Date: Thu, 12 Jun 2003 16:24:02 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Installing Perl 5.8
Message-Id: <CO1Ga.394$%H.49956889@newssvr14.news.prodigy.com>

In comp.unix.solaris Philip Juels <pjuels@rics.bwh.harvard.edu> wrote:

> 1)  I understand its NOT a good idea to remove/replace the Perl
> version bundled with Solaris...okay that's fine, I'll just install the
> Sunfreeware package which puts it in /usr/local, but...
> 2)  How do I install CPAN modules to the newer Perl rather than the
> default old one?

Whichever perl is in your path when you run 'perl Makefile.PL'

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


------------------------------

Date: Thu, 12 Jun 2003 13:34:27 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Installing Perl 5.8
Message-Id: <4nel1zjj30.fsf@lockgroove.bwh.harvard.edu>

On Thu, 12 Jun 2003, daveuhring@yahoo.com wrote:
> On Thu, 12 Jun 2003 07:23:48 -0700, Philip Juels wrote:
>> I'd like to install Perl 5.8.0 on our Fire 880 Solaris box, but I
>> have a few concerns:
>> 
>> 1) I understand its NOT a good idea to remove/replace the Perl
>> version bundled with Solaris...okay that's fine, I'll just install
>> the Sunfreeware package which puts it in /usr/local, but...  2) How
>> do I install CPAN modules to the newer Perl rather than the default
>> old one?
> 
> The Solaris scripts which require perl use the full path to the
> required version.
> 
> ln -s /usr/local/bin/perl /usr/bin/perl

I would do a CPAN autobundle of the old Perl:

/usr/bin/perl -MCPAN -e'autobundle'

before disabling it like this, just to be safe.

Ted


------------------------------

Date: Thu, 12 Jun 2003 13:35:55 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Installing Perl 5.8
Message-Id: <4nadcnjj0k.fsf@lockgroove.bwh.harvard.edu>

On 12 Jun 2003, pjuels@rics.bwh.harvard.edu wrote:
> 2) How do I install CPAN modules to the newer Perl rather than the
> default old one?

/usr/local/bin/perl -MCPAN -e'shell'

or

/usr/local/bin/perl -MCPAN -e'install Module::Name'

Ted


------------------------------

Date: 12 Jun 2003 10:05:17 -0700
From: wwlou@hotmail.com (Daniel Lou)
Subject: Multiple threads append data to the same file
Message-Id: <b6df9949.0306120905.6ea14a40@posting.google.com>

I tried to use semaphore to synchronize writes to the same file by
multiple threads, but it doesn't work properly. In the following
testing script,
40 threads simultaneously append lines (consisting of 10 'A's or 10
'B's) to a file "test.txt". However, quite a few lines in "test.txt"
aren't 10 'A's or 10 'B's. Where does it go wrong?

-Daniel

---------------------------------------------------------
use strict;
use threads;
use Thread::Semaphore;    

my $thrd_sem   = new Thread::Semaphore;
open (OUTPUT, ">>test.txt");

## create 20 threads for writing As and Bs to the file

$thrd_sem->down;
my $thr_id;
while ($thr_id++ < 20) { threads->new(\&write_a); }
while ($thr_id--) { threads->new(\&write_b); }
$thrd_sem->up;

## wait for all threads to return

foreach my $thr (threads->list) { 
   if ($thr->tid && !threads::equal($thr, threads->self)) { 
        $thr->join; 
   } 
}
close(OUTPUT);

## sub routine that appends "A" lines to the file
sub write_a {
	for (my $i = 0;$i < 10000; $i++) {
		$thrd_sem->down;
		print OUTPUT "AAAAAAAAAA\n";
		$thrd_sem->up;
	}
}
## sub routine that appends "B" lines to the file
sub write_b {
	for (my $i = 0;$i < 10000; $i++) {
		$thrd_sem->down;
		print OUTPUT "BBBBBBBBBB\n";
		$thrd_sem->up;
	}
}


------------------------------

Date: 12 Jun 2003 18:25:24 GMT
From: ctcgag@hotmail.com
Subject: Re: newbie: will a big array hurt performance?
Message-Id: <20030612142524.227$Zb@newsreader.com>

Ge Jun <gejun@cs.iastate.edu> wrote:
> Hi Everyone,
>
> I have a file to read and to deal with each line.  I have two approach
> to do it, one is using a scalar and to read lines one by one, while the
> other way is to use an arrry @line.  My question is: if the file is big,
> @line should have a big buffer, will this hurt performance?

Eventually.  How big is big?

I tend to be aggressive about slurping files into arrays.

If slurping doesn't get you any benefit whatsoever, which seems
to be the case in the code you show, don't slurp.

If slurping does make the code even a little bit more concise, or
easier to program, or easier to debug, or more flexible, then I will slurp
it unless I anticipate that doing so would exhause physical memory (or
compete with other memory-hungry processes).  You can't save unused
memory for a rainy day.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


------------------------------

Date: Thu, 12 Jun 2003 14:31:59 -0500
From: "Brian Abernathy" <babernat@purdue.edu>
Subject: regex help
Message-Id: <bcakc6$ppc$1@mozo.cc.purdue.edu>

Is there a way to auto-escape all special characters in a string?




------------------------------

Date: Thu, 12 Jun 2003 20:36:44 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: regex help
Message-Id: <mbudash-DD93FC.13364412062003@typhoon.sonic.net>

In article <bcakc6$ppc$1@mozo.cc.purdue.edu>,
 "Brian Abernathy" <babernat@purdue.edu> wrote:

> Is there a way to auto-escape all special characters in a string?

in what enviroment? for what purpose?
-- 
Michael Budash


------------------------------

Date: Thu, 12 Jun 2003 14:12:45 -0700
From: TruthXayer <TruthXayer@yahoo.com>
To: Brian Abernathy <babernat@purdue.edu>
Subject: Re: regex help
Message-Id: <3EE8ECCD.93FC973@yahoo.com>

Brian Abernathy wrote:
> =

> Is there a way to auto-escape all special characters in a string?

Read perldoc perlre
Pay special attention to:
	\Q
	use customre;

-- =

thanks
-Tr=DCtH


------------------------------

Date: Thu, 12 Jun 2003 16:46:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regex help
Message-Id: <slrnbeht68.3ap.tadmc@magna.augustmail.com>

Brian Abernathy <babernat@purdue.edu> wrote:

> Is there a way to auto-escape all special characters in a string?


That would depend on what it is that defines "specialness"...


Perhaps this will do:

   perldoc -f quotemeta


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 12 Jun 2003 11:29:03 -0400
From: Bernard Cosell <bernie@rev.net>
Subject: Re: Sanitizing a regular expression
Message-Id: <sr5hevcghj97vdn9nbb6m2t80ui92scko8@4ax.com>

On Thu, 12 Jun 2003 10:57:00 -0400, Bernard Cosell <bernie@rev.net>
wrote:

>I need to 'sanitize' a user-supplied regular expression and I'm not
>sure how to manage it. ...

I ought to at least say what I *am* doing now -- as a desperation
brute-force starting point, I just '\' *everything* in the
user-supplied string.  

What I'd like to do is give the users "normal"/classical REs --
alternation, char classes, grouping, quantifiers -- without giving the
user access to any of Perl's "fancier" machinery..  Short term, as I
said, I'm just brute-force emasculating the RE, but is there some
clever way to allow _only_ "plain-jane" REs?

  /Bernie\


------------------------------

Date: Thu, 12 Jun 2003 13:29:38 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Sanitizing a regular expression
Message-Id: <4nisrbjjb1.fsf@lockgroove.bwh.harvard.edu>

On Thu, 12 Jun 2003, bernie@rev.net wrote:
> What I'd like to do is give the users "normal"/classical REs --
> alternation, char classes, grouping, quantifiers -- without giving
> the user access to any of Perl's "fancier" machinery..  Short term,
> as I said, I'm just brute-force emasculating the RE, but is there
> some clever way to allow _only_ "plain-jane" REs?

Why not give the users a simple query language which can be easily
translated (e.g. by Parse::RecDescent) into regular expressions?
Advantages:

- users don't have to learn Perl regexes (most won't)

- your query language will carry into other languages (e.g. Perl 6,
  Java, etc.) without syntax changes.

- the query language can look like English (or other languages)

Ted


------------------------------

Date: 12 Jun 2003 17:39:46 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: Sanitizing a regular expression
Message-Id: <bcadt2$h3dsn$1@ID-24002.news.dfncis.de>

Bernard Cosell wrote:
> I need to 'sanitize' a user-supplied regular expression and I'm not
> sure how to manage it.
[...]
> I can
> see that I need to scan for and remove (?{...})

at least that you don't have to remove; that's only allowed
with
 use re 'eval';

see
 perldoc re
for more information.

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -


------------------------------

Date: Thu, 12 Jun 2003 13:48:59 -0400
From: Bernard Cosell <bernie@rev.net>
Subject: Re: Sanitizing a regular expression
Message-Id: <qnehev8ss7u7aid874nca0egqv9e5jinmj@4ax.com>

On Thu, 12 Jun 2003 13:29:38 -0400, Ted Zlatanov <tzz@lifelogs.com>
wrote:

>On Thu, 12 Jun 2003, bernie@rev.net wrote:
>> What I'd like to do is give the users "normal"/classical REs --
>> alternation, char classes, grouping, quantifiers -- without giving
>> the user access to any of Perl's "fancier" machinery..  Short term,
>> as I said, I'm just brute-force emasculating the RE, but is there
>> some clever way to allow _only_ "plain-jane" REs?
>
>Why not give the users a simple query language which can be easily
>translated (e.g. by Parse::RecDescent) into regular expressions?

That's what I'm contemplating doing.  Coming up with one isn't all
that easy, but I guess the idea is as you suggest: not even a query
language, but use something I can specify with a grammar [which is
easy to do for classical REs] and then write a little parser/compiler
to turn it into the corresponding Perl RE...

>- users don't have to learn Perl regexes (most won't)

As far as that goes, Perl REs *ARE* the same as classical ones --
given I'm going to limit the users to "only classical", that subset of
Perl's RE machinery is fine.

>- your query language will carry into other languages (e.g. Perl 6,
>  Java, etc.) without syntax changes.
>
>- the query language can look like English (or other languages)

I'm a very-old-line Computer Science type, so I fine REs [and the
grammars for them] kind of ingrained --- and I hate to reinvent the
wheel...  are there such query languages around?  In any event, thanks
for the suggestion -- I'd hoped for something simpler but medium-term
[I'll stick with the \'ing short term..:o)] I'll try whipping up a
simple grammar for what I'm willing to allow the users to do and then
cobble up a little bit of Perl to turn that into an actual 'qr'.

  /Bernie\



------------------------------

Date: 12 Jun 2003 08:41:01 -0700
From: almir_7@yahoo.com (Almir)
Subject: Search through Array and evaluate the two
Message-Id: <72ddae16.0306120741.5e8d713a@posting.google.com>

I guess i wanted some guidance with the following code. I wanted to
see if anyone could point me in right direction or notice a problem
with me code. I need to check the whole array for the previous
occurance of that barcode with same date. To count that recort the
time difference is got to be 20minutes, with everything in between
gets skipped.I did the same quiery twice first off to populate the
array, so that it can be searched at all by grep. Maybe someone has a
good example how to do this or a better idea, but i does have to be in
perl...thanx once again




$i=0;
$db->Sql("SELECT plog.Barcode, plog.Auth_Date, plog.Auth_Time FROM
plog WHERE(((plog.Auth_Date) Between #3/1/2003# And #3/31/2003#) AND
((plog.Key)=[key]))"); #distinct users for the month
if ($db->FetchRow())
{
    ($barcode, $mdate, $mtime) = $db->Data();
           
    $code[$i] = $barcode;
    $dates[$i] = $1 if $mdate =~ /((\d\d\d\d)-(\d\d)-(\d\d))/;
    $times[$i] = $1 if $mtime =~ /(\d\d:\d\d:\d\d)/;
       
}

@bfound = 0;
@dfound = 0;
@tfound = 0;
$i=1;
$db->Sql("SELECT plog.Barcode, plog.Auth_Date, plog.Auth_Time FROM
plog WHERE(((plog.Auth_Date) Between #3/1/2003# And #3/31/2003#) AND
((plog.Key)=[key]))"); #distinct users for the month
while ($db->FetchRow())
    {
        ($barcode, $mdate, $mtime) = $db->Data();   #read in data by
row
        
        $adate = $1 if $mdate =~ /((\d\d\d\d)-(\d\d)-(\d\d))/;
        $atime = $1 if $mtime =~ /(\d\d:\d\d:\d\d)/;
        
        @patron = ($barcode, $adate, $atime);
        print "@patron\n";
        
        
        if (@bfound = grep /$barcode/, @code)   #check if there is the
previous barcode occurance
        {
            if (@dfound = grep /$adate/, @dates)    #check if there is
the previous date occurance
            {
                    if ($tfound = grep /$atime/, @times)    #check if
there is a previous time occurance
                    {
                        
                    }
                    else
                    {
                        ($hour, $min, $sec) = ($times[$tfound] =~
m/(\d+):(\d+):(\d+)/);
                        $checkoff = ((($hour * 60)*60) + ($min * 60) +
$sec);          #convert the time in seconds
                        
                        ($ahour, $amin, $asec) = ($atime =~
m/(\d+):(\d+):(\d+)/);
                        $inseconds = ((($ahour * 60)*60) + ($amin *
60) + $asec);        #convert the time in seconds
                        
                        if ($inseconds != $checkoff)  #check if the
time is equal
                        {
                            if ($inseconds >= $checkoff + 1200) 
#check if the time is bigger
                            {
                                $i+=1;
                                $code[$i] = $barcode;
                                $dates[$i] = $adate;
                                $times[$i] = $atime;
                                $number+=1;
                            }
                        }
                        else
                        {
                            $i+=1;
                        }
                    }
                
            }
            else
            {
                $i+=1;
                $code[$i] = $barcode;
                $dates[$i] = $adate;
                $times[$i] = $atime;
                $number+=1;
            }
        }
        else
        {
           $i+=1;
           $code[$i] = $barcode;
           $dates[$i] = $adate;
           $times[$i] = $atime;
           $number+=1; 
        }
}
print "Number of Sessions: $number\n"


Is there a module that returns me the last occurance of a barcode within the array?


------------------------------

Date: 12 Jun 2003 19:15:22 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Search through Array and evaluate the two
Message-Id: <bcajga$8p4@dispatch.concentric.net>


"Almir" <almir_7@yahoo.com> wrote in message
news:72ddae16.0306120741.5e8d713a@posting.google.com...
> I guess i wanted some guidance with the following code. I wanted to
> see if anyone could point me in right direction or notice a problem
> with me code. I need to check the whole array for the previous
> occurance of that barcode with same date. To count that recort the
> time difference is got to be 20minutes, with everything in between
> gets skipped.I did the same quiery twice first off to populate the
> array, so that it can be searched at all by grep. Maybe someone has a
> good example how to do this or a better idea, but i does have to be in
> perl...thanx once again
>
>

>
> Is there a module that returns me the last occurance of a barcode within
the array?

Am only attempting to answer your final question.  In general, you could
determine the last occurrence of an element within an array with code like
this:

    my @barcodes = qw|alpha beta gamma delta alpha epsilon beta zeta eta
theta gamma|;
    my %seenlast = ();
    for (my $i=0; $i<=$#barcodes; $i++) {
        if (defined $seenlast{$barcodes[$i]}) {
            $seenlast{$barcodes[$i]} = $i if $i > $seenlast{$barcodes[$i]};
        } else {
            $seenlast{$barcodes[$i]} = $i;
        }
    }

    foreach (sort keys %seenlast) {
        print "Element:  $_\tLast seen at index:  $seenlast{$_}\n";
    }

Jim Keenan




------------------------------

Date: Thu, 12 Jun 2003 13:15:36 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Search through Array and evaluate the two
Message-Id: <Pine.GSO.4.21.0306121312350.23188-100000@mtwhitney.nsc.com>

On 12 Jun 2003, James E Keenan wrote:

(Snipped) ... 

> In general, you could
> determine the last occurrence of an element within an array with code like
> this:
> 
>     my @barcodes = qw|alpha beta gamma delta alpha epsilon beta zeta eta
> theta gamma|;
>     my %seenlast = ();
>     for (my $i=0; $i<=$#barcodes; $i++) {
>         if (defined $seenlast{$barcodes[$i]}) {
>             $seenlast{$barcodes[$i]} = $i if $i > $seenlast{$barcodes[$i]};
>         } else {
>             $seenlast{$barcodes[$i]} = $i;
>         }
>     }




Seems simpler to replace the 'for' loop with a hash slice:

@seenlast{@barcodes} = (0 .. $#barcodes);



>     foreach (sort keys %seenlast) {
>         print "Element:  $_\tLast seen at index:  $seenlast{$_}\n";
>     }
> 

-- 
Regards,
Steven



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5112
***************************************


home help back first fref pref prev next nref lref last post