Re: array searching

2007-01-14 Thread John W. Krahn
Jim Canon wrote: > > On 1/14/07, John W. Krahn <[EMAIL PROTECTED]> wrote: >> >> Jim Canon wrote: >> > >> > Thank you very much for the response, it has helped me begin to >> > understand how regular expressions work. I see that /(\d+)$/ >> > matches the numbers until the end of line in >> > >> >

Re: array searching

2007-01-14 Thread Jim Canon
By numbers in front I am referring to word1 word2 job2006 in the element: word1 word2 job2006 three four five six community job555 It seems that /(\d+)$/ matches word1 word2 job2006 job555 I was reviewing http://perldoc.perl.org/perlre.html but am having trouble determining the best way to match j

Re: array searching

2007-01-14 Thread John W. Krahn
Jim Canon wrote: > > Thank you very much for the response, it has helped me begin to understand > how regular expressions work. I see that /(\d+)$/ matches the numbers > until the end of line in > > @job1 = qw( > job555 > job572 > job8433 > job873 > job594 > job4663 > job2221 > job2223 >

Re: array searching

2007-01-12 Thread Rob Dixon
Jim Canon wrote: > Hi, > > This is my first question, I appreciate any information you provide. I want > to compare the numbers after : in @jn to the numbers after job in @job1 and > @job2. > > > @jn = > JN.2007:555 > JN.2007:8433 > JN.2007:594 > JN.2007:111 > JN.2007:4663 > JN.2007.321 > JN.2007:

Re: array searching

2007-01-11 Thread John W. Krahn
Jim Canon wrote: > Hi, Hello, > This is my first question, I appreciate any information you provide. I want > to compare the numbers after : in @jn to the numbers after job in @job1 and > @job2. > > [ snip ] > > I want to put what is missing in @jn compared to @job1 and @job2 in > @jobMissing :

array searching

2007-01-11 Thread Jim Canon
Hi, This is my first question, I appreciate any information you provide. I want to compare the numbers after : in @jn to the numbers after job in @job1 and @job2. @jn = JN.2007:555 JN.2007:8433 JN.2007:594 JN.2007:111 JN.2007:4663 JN.2007.321 JN.2007:2221 @job1 = job555 job572 job8433 job873

Re: Very slow array searching

2003-07-29 Thread John W. Krahn
Paul Archer wrote: > > 3:20pm, Ramprasad wrote: > > > > Rafaqat Ali Chaudhry wrote: > > > > > > The array has at least 20K elements. This piece of code is taking up > > > almost 100% of the CUP cycles. Would somebody please suggest some > > > alternative solution. > > > > You can improve the code

Re: Very slow array searching

2003-07-29 Thread Paul Archer
In addition to the suggestions already given, you could sort your array, and then look at the middle and cut it in half (potentially several times). I forget the name for this technique, though... For example, you have 1000 elements, sorted. You compare your number to the 500th element. If it's hi

RE: Very slow array searching

2003-07-29 Thread Jeff 'japhy' Pinyan
On Jul 29, Bob Showalter said: >Bob Showalter wrote: >> ... >> A more efficient iterative approach using a numeric equality test >> would be: >> >>sub checkNumber { >> $_[0] == $_ && return 1 for @numbers; >> return; >>} >> >> This returns 1 for a match and undef for no match.

RE: Very slow array searching

2003-07-29 Thread Bob Showalter
Bob Showalter wrote: > ... > A more efficient iterative approach using a numeric equality test > would be: > >sub checkNumber { > $_[0] == $_ && return 1 for @numbers; > return; >} > > This returns 1 for a match and undef for no match. Heck, you can even leave off the last "

RE: Very slow array searching

2003-07-29 Thread Bob Showalter
Rafaqat Ali Chaudhry wrote: > Dear all, > > I've a function which searches a given number from an array and > returns the result. > > Function: > > 1.sub checkNumber($) > 2.{ > 3.my ($l_number) = @_; > 4.my $l_status; > 5.my @matches= grep { /$l_numbe

Re: Very slow array searching

2003-07-29 Thread Ramprasad
Rafaqat Ali Chaudhry wrote: Dear all, I've a function which searches a given number from an array and returns the result. Function: 1. sub checkNumber($) 2. { 3. my ($l_number) = @_; 4. my $l_status; 5. my @matches= grep { /$l_number/ } @numbers;

Very slow array searching

2003-07-29 Thread Rafaqat Ali Chaudhry
Dear all, I've a function which searches a given number from an array and returns the result. Function: 1. sub checkNumber($) 2. { 3. my ($l_number) = @_; 4. my $l_status; 5. my @matches= grep { /$l_number/ } @numbers; 6. if (@match

RE: Very slow array searching

2003-07-29 Thread Rafaqat Ali Chaudhary
Thanks George. It reduced the total time to almost 50%. Rafaqat Ali Chaudhary -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of George P. Sent: Tuesday, July 29, 2003 11:57 To: Rafaqat Ali Chaudhary Cc: [EMAIL PROTECTED] Subject: Re: Very slow array

Re: Very slow array searching

2003-07-28 Thread George P.
On Tue, 29 Jul 2003, Rafaqat Ali Chaudhary wrote: > Dear all, > > I've a function which searches a given number from an array and returns > the result. > > Function: > > 1.sub checkNumber($) > 2.{ > 3.my ($l_number) = @_; > 4.my $l_status; > 5.my @ma

Very slow array searching

2003-07-28 Thread Rafaqat Ali Chaudhary
Dear all, I've a function which searches a given number from an array and returns the result. Function: 1. sub checkNumber($) 2. { 3. my ($l_number) = @_; 4. my $l_status; 5. my @matches= grep { /$l_number/ } @numbers; 6. if (@match