Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Array inside hashes

by atl (Pilgrim)
on Jul 22, 2000 at 11:50 UTC ( [id://23893]=note: print w/replies, xml ) Need Help??


in reply to Array inside hashes

Good morning! :-)

Here's a working script:

atl@companion:~/perl > cat aih.pl #!/usr/bin/perl -w %hash = (name => foo, list => [1, 2, 3]); foreach( keys %hash ){ print "key: $_, value: $hash{$_}\n"; } $ref = $hash{list}; @array = @$ref; foreach(@array){print "array: $_\n";} atl@companion:~/perl > aih.pl Unquoted string "foo" may clash with future reserved word at ./aih.pl +line 3. key: name, value: foo key: list, value: ARRAY(0x80cf9a4) array: 1 array: 2 array: 3 atl@companion:~/perl >
Since I didn't have my cup of tea yet (another sign of PM addiction: checking PM before making tea/coffee) I'll just let the code speak. ;-))

Ok, one comment. From the perlop manpage:

The => digraph is mostly just a synonym for the comma operator.
So your code means in essence
%hash = (name, foo, list, 1, 2, 4);
Have fun ...

Andreas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found