Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Hash references and efficiency

by jsprat (Curate)
on Aug 03, 2002 at 04:41 UTC ( [id://187295]=note: print w/replies, xml ) Need Help??


in reply to Hash references and efficiency

Yes, it populates the hash. You are dereferencing the original hashref, creating a copy and assigning it to a new hash.

If you don't like typing curly brackets, try the arrow syntax ($hashref->{key}). BTW, treating a hashref differently than a regular hash can be considered a good thing when you review old code.

Replies are listed 'Best First'.
Re: Re: Hash references and efficiency
by simeon2000 (Monk) on Aug 03, 2002 at 13:26 UTC
    I've actually always coded like this:

    my %hash = ( jim => 'fred', babs => 'buster' ); my $href = \%hash; print $$href{jim}, "\n";

    But you're saying that the $href->{jim} syntax is preferred?

    --
    perl -e "print qq/just another perl hacker who doesn't grok japh\n/"
    simeon2000|http://holdren.net/

      Why are you doing it like that? There's no reason to use a hashref in the above code. Use refs for complex data structures or for passing hashes and arrays back and forth between subs.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2025-06-23 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.