Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Anonymous Data Structures

by FunkyMonk (Bishop)
on Jun 01, 2007 at 11:12 UTC ( [id://618697]=note: print w/replies, xml ) Need Help??


in reply to Anonymous Data Structures

Anonymous hashes & arrays, as you stated, are just hashes and arrays that don't have a name. They are only useful when used as a reference:

my $hashref = { A => 1, B => 2 }; my $arrayref = [ 1, 2, 3 ];

You would then access the elements of the references using ->:

print $hashref->{B}; # 2 print $arrayref->[2]; # 3

or by

print %$hashref{B}; # 2 print @$arrayref[2]; # 3

I much prefer ->, for what it's worth

Replies are listed 'Best First'.
Re^2: Anonymous Data Structures
by blazar (Canon) on Jun 04, 2007 at 08:21 UTC
    I much prefer ->, for what it's worth

    As a general rule, /me too. Though as with most things, there are situations in which it is best suited and situations in which the other way is preferable. Also, they're not equivalent in all respects.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2025-12-09 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (89 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.