Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want to be able to iterate through @numbers, comparing each value to @needed. When there is a match, I want to get the match and all the values until the next match.@numbers = ('25', '12', '32','56','45','21','65'); @needed = ('25','32','45','65');
Thankyou monks, I appreciate your help. xe.g. get 25 12 32 and 45 21 65
for (my $i=0; $i<@numbers; $i++) { # psudocode # # if $numbers[$i] matches a value in @needed; # push @found, all the numbers until the next match for (my $k = 0; $k < @needed; $k++) { if ($numbers[$i] == $needed[$k]) { push @found, $numbers[$i]; # not sure how to carry on until the next match! } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: comparing values between two arrays
by merlyn (Sage) on May 20, 2003 at 10:08 UTC | |
|
Re: comparing values between two arrays
by broquaint (Abbot) on May 20, 2003 at 10:15 UTC | |
|
Re: comparing values between two arrays
by dbush (Deacon) on May 20, 2003 at 10:24 UTC | |
|
Re: comparing values between two arrays
by OM_Zen (Scribe) on May 20, 2003 at 16:51 UTC |