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.
In reply to Flag variables by oakbox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |