Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Hash problem: each() failure

by DigitalKitty (Parson)
on Feb 23, 2008 at 18:12 UTC ( #669760=note: print w/replies, xml ) Need Help??


in reply to Hash problem: each() failure

Hi Anonymous Monk.

As Corion mentioned, you used the anonymous hash syntax, i.e., $name_of_hash = { ... };

Assigning a list to a hash variable will result in the key/value pair(s) being created.
use warnings; use strict; my %Cls = qw( P a N b U c ); print %Cls, "\n\n"; while ( my ($k, $v) = each( %Cls ) ) { print "$k => $v\n"; }

Update: Fixed typo by changing %name_of_hash = { ... }; to $name_of_hash = { ... }; after ikegami++ noticed it. Thanks.

Hope this helps,
~Katie

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://669760]
help
Chatterbox?
[chacham]: I'm sure this is old, but i just came across it: If you put a million monkeys at a million keyboards, one of them will eventually write a Java program. The rest of them will write Perl programs.
[LanX]: lol
[Corion]: Woo hoo! A new Auralnauts episode!
LanX mean unfair and funny
[LanX]: but most java code looks like from one million monkey using eclipse. ..
[Eily]: ah yes, perl's motto, There Is More Than One Monkey Typing It

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2018-04-23 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?