In addition to what
bobf said, writing
$_ == 1 is dangerous because it is too easy to drop an = and assign rather than compare. (Warnings will catch that, but you probably don't have warnings.)
Depending on the circumstances, where one person would use your approach I might have an array of references to closures. Then I just call them. Like this:
my @array = (\&do_where_var_is_1,\&do_something_else, \&do_something);
+ # etc
$_->() for @array;
This may look convoluted, but when you are building up your array in code it is as easy to put code references in as values, and now you don't have to synchronize between the if logic where you do stuff and the logic where you build the array.
Also this code snippet has very badly named variables, arrays and functions. Probably that is because it is an example, but do be sure that real code is of better quality.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
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.