As for the "obsolete" part, i used it --evidently badly-- as a synonym to "since there is no other code
... in the foreach block".
Of course i was only refering to this snippet since
next is invaluable in loop control. But i'm sure you knew that already. ;)
As for the grep gotcha, here is the situation. Given this code:
my $line = "Alpha and some beta junk here";
my @keywords = qw(alpha beta gamma);
foreach (grep { $line =~ /$_/i } @keywords) {
$_ = rand;
}
foreach (@keywords) { print "$_\n" }
We get when run:
0.623870849609375
0.16607666015625
gamma
Grep aliases the current value of $_ to the original array element, and thus modifying it actually tampers our original data. It wasn't any special complication really, but has the potential to obfuscate a bug or two.
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.