in reply to grep { $var } @arr
Another option is to use a subroutine reference instead of a string:
#! perl use strict; use warnings; my @arr = (1, 2, 3, 4, 5); my $pat = sub { $_[0] < 3 }; my @res; @res = grep {$_ < 3} @arr; print "Literal:\t@res\n"; @res = grep { $pat->($_) } @arr; print "Variable:\t@res\n";
Output:
0:52 >perl 939_SoPW.pl Literal: 1 2 Variable: 1 2 0:52 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|