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

Re: Confused on Scalar/Hash

by stevieb (Canon)
on Apr 02, 2018 at 15:34 UTC ( [id://1212174]=note: print w/replies, xml ) Need Help??


in reply to Confused on Scalar/Hash

That's a scalar that contains a reference to a hash.

Observe (untested):

my %hash = ( a => 1, b => 2, ); my $href = \%hash;

The coder just skipped the intermediary step of taking a reference to the hash, and instead constructed it as a hash reference directly. To get information from the hash as I depicted above, you access it normally:

my $thing = $hash{a};

In the case of the hash reference, you have to dereference first:

my $thing = $href->{a};

You can dereference the entire hash reference and put it into a new hash if you please, but there's not often reason to do so unless you need a copy of the entire structure:

my %hash = %{ $href };

See perlreftut.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 06:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found