oakbox has asked for the wisdom of the Perl Monks concerning the following question:

A few weeks ago I was reading a list of 'don'ts' in perl. One of the things to avoid is the following:

my $flag = 0; foreach my $var (@somearray){ if($var eq "foo"){ $flag = 1; last;} } if($flag eq "1"){ &someaction;}

I do this kind of thing All The Time and I don't know a) Why is it wrong? and b) How else would I go about it?

Checking if $var is equal to "foo" might be some other, more complex, calculation or maybe a database call of some kind.