in reply to Foreach Loops
Updated: MapCar was a bad choice. This one is actually pretty cool:
Caution: Contents may have been coded under pressure.
Obviously, modifying $line isn't going to affect @arr, though. To do that, you'd have to douse Algorithm::Loops 'NestedLoops'; my $iter = NestedLoops([\@arr, do {my $i=0; sub {[$i++]}} ]); while (my ($line, $x) = &$iter) { print "$x: $line\n"; }
use Algorithm::Loops 'NestedLoops'; my $iter = NestedLoops([[\(@arr)], do {my $i=0; sub {[$i++]}} ]); while (my ($line, $x) = &$iter) { for my $line ($$line) { print "$x: $line\n"; $line = 'X'; } } print "@arr\n";
Caution: Contents may have been coded under pressure.
|
---|
In Section
Seekers of Perl Wisdom