in reply to Thoughts on the magicality of @_ and $_
Of course this is simplified, but doesn't it seem like $name should be equal to "eugene" after the loop? But it isn't. It's undefined, because it was undefined at the start of the loop. So if you want to do something with the elements of the array and end up storing the last one as a side effect you have to do it in a similar way to this:use strict; my $name; foreach $name (qw/alfred benjamin casey donald eugene/) { print "$name\n"; } print "*$name*\n";
Which has never seemed as DWIMish as I wished for.use strict; my $name; foreach my $loopname (qw/alfred benjamin casey donald eugene/) { $name = $loopname; print "$name\n"; } print "*$name*\n";
;)
jarich
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Thoughts on the magicality of @_ and $_
by Aristotle (Chancellor) on Jul 01, 2002 at 14:17 UTC |