Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Copying a hash to an array of hashes.

by Joost (Canon)
on Sep 18, 2009 at 23:41 UTC ( #796226=note: print w/replies, xml ) Need Help??


in reply to Re^2: Copying a hash to an array of hashes.
in thread Copying a hash to an array of hashes.

Perl references are a bit unintuitive, especially when combined with list context.

The main problem you're running into is that putting a hash in list context gives you a flat list containing the keys and values of the hash interleaved, so:

my %array = ( a => 1, b => 2); my @list = %array;
Now @list (*) will contain either ('a',1,'b',2) or ('b',2,'a',1)

Just like

my @list1 = (1,2); my @list2 = (@array,3,4);
@list2 will contain (1,2,3,4).

But references will not be subject to flattening.

I strongly recommend the Camel book for anyone interested in the truth on perl, straight from the horse's mouth. Especially if they're already past the easy stuff. It's not the easiest book but it reads well and for an all round reference and "concept" book on perl, you can't beat it.

(*) please don't ask me about the differences between lists and arrays, it's subtle. forget it for now.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://796226]
help
Chatterbox?
[Corion]: Huh. I wasn't aware that you cannot segregate Python 2 and Python 3 modules... Hopefully Perl 6 module use C6AN and thus avoid the problem...
[hippo]: I very much hope so.
[moritz]: there are already some (very few) Perl 6 modules on CPAN, but in a way that the p5 indexer avoids them
[hippo]: It's confusing enough to have the Perl6:: namespace which isn't for Perl6 but for features from that ported into Perl.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-01-24 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (203 votes). Check out past polls.