[Israel.pm] checking for presence of a value in a list

Amir E. Aharoni amir.aharoni at gmail.com
Wed Aug 15 06:41:42 PDT 2007

On 15/08/07, Peter Gordon <peter at pg-consultants.com> wrote:
> @w = (1, 2, 3, 4, 5) ;
> grep { $w->{$_} ++ } @w ;
> print "found\n" if exists $w->{3} ;

Hmm, it's a nice Perlish trick, but to make it run under use strict, i
had to rewrite it like this:

my @w = qw(Reuven Shimon Levi Yehuda);
my $w = { };
grep { $w->{$_} ++ } @w;

print "found\n" if exists $w->{'Levi'};

... And that doesn't improve readability and maintainability. So this
would be too Perlish for production code that will have to be
maintained for years to come.

However, it can be OK, if it brings up a significant performance boost
... does it?

More information about the Perl mailing list