Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: foreach loops

by Mr. Muskrat (Canon)
on Dec 22, 2004 at 06:30 UTC ( [id://416709]=note: print w/replies, xml ) Need Help??


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.

my %hash; my @array = qw( ABC DEF GHI ); $hash{$_}++ for (@array); # $_ is the loop variable.
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 ); for my $key (@array) { $hash{$key}++ }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://416709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found