in reply to foreach loops
Something that has not been mentioned in this thread or in for loops is the reversed form of the for/foreach loop.
This code is no different than the following except that the for comes at the end (and that you are forced to use $_ as the loop variable).my %hash; my @array = qw( ABC DEF GHI ); $hash{$_}++ for (@array); # $_ is the loop variable.
my %hash; my @array = qw( ABC DEF GHI ); for my $key (@array) { $hash{$key}++ }
|
|---|