in reply to Re^4: Missing $ on loop variable
in thread Missing $ on loop variable
As for the grep gotcha, here is the situation. Given this code:
We get when run:my $line = "Alpha and some beta junk here"; my @keywords = qw(alpha beta gamma); foreach (grep { $line =~ /$_/i } @keywords) { $_ = rand; } foreach (@keywords) { print "$_\n" }
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.0.623870849609375 0.16607666015625 gamma
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Missing $ on loop variable
by revdiablo (Prior) on Dec 03, 2005 at 19:27 UTC |