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

Re: Why does an array "dissolve" into a hash?

by Athanasius (Archbishop)
on Aug 20, 2015 at 01:20 UTC ( [id://1139244]=note: print w/replies, xml ) Need Help??


in reply to Why does an array "dissolve" into a hash?

Hello Cody Fendant,

As LanX says, it’s a list assignment. So

my %h = (foo => 100, bar => 333, san => @a);

is actually

my %h = ('foo', 100, 'bar', 333, 'san', '8', 'foo', '666');

The second assignment to key foo overwrites the first, so when the assignment is complete, $h{foo} is '666'.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Why does an array "dissolve" into a hash?
by Cody Fendant (Hermit) on Aug 20, 2015 at 03:54 UTC

    Ah, that makes sense. Thank you. Is the use of the word "dissolve" normal here?

      "Flattened into a list" is the commonly used, though it's a bit of a misnomer. The array doesn't get flattened into another data structure; an array simply returns its elements in list context.
      Never heard it used that way before.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-03-29 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found