in reply to Compare all array values without a loop
if ( grep { $_ eq $foobar} @array ) { }
Update: Use the above code if you really want to compare all array values (which is what you said). If you really want to just know if the value is in the array (and then stop searching), you might try the following, which might perform better in certain situations:
use List::Util qw(first); if ( first { $_ eq $foobar } @array ) { }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Compare all array values without a loop
by rjbs (Pilgrim) on Oct 19, 2004 at 14:25 UTC | |
by edan (Curate) on Oct 19, 2004 at 14:41 UTC | |
|
Re^2: Compare all array values without a loop
by ihb (Deacon) on Oct 20, 2004 at 00:21 UTC | |
|
Re^2: Compare all array values without a loop
by welchavw (Pilgrim) on Oct 20, 2004 at 14:23 UTC | |
|
Re^2: Compare all array values without a loop
by Anonymous Monk on Oct 19, 2004 at 14:22 UTC |