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.
oakbox
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|