[LA.pm] Double versus single quotes

Terrence Brannon metaperl at urth.org
Tue Nov 25 18:29:33 CST 2003


Jeff Yoak wrote:

>What's wrong with:
>
>if(grep {$_ eq 'banana'} @fruit){
>	print "The monkeys rejoice!\n";
>}
>
>The answer is nothing.  You just don't have enough fruit to care.  It is
>better to not continue through @fruit once you find a banana.  You would
>prefer:
>
>foreach my $fruit (@fruit){
>	if($fruit eq "banana"){
>		print "The monkeys rejoice!\n";
>		last;
>	}
>}
>
>You might still further prefer:
>
>my %fruit;
>@fruit{@fruit}=();
>print ... if exists $fruit{'banana'};
>  
>
>
Let's not forget:

http://search.cpan.org/~gbarr/Scalar-List-Utils-1.13/lib/List/Util.pm

which allows
if (first { $_ = $desired } @fruit) {
    print "$desired found";
}






More information about the Losangeles-pm mailing list