Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Multilayer dereferencing question

by Anonymous Monk
on Mar 13, 2018 at 13:53 UTC ( [id://1210822]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm messing around with dereferencing arrays, and was curious why the following portion of this code involving the hash doesn't work:
my @array1 = ( 'abc', 'def', 'ghi', 'jkl' ); my $s1 = \@array1; my $s2 = \$s1; my %hash = ( 'key' => $s1 ); my $hash_s = \%hash; print(@$$s2); # works print(@$$hash{'key'}); # doesn't work
If I remove the @, both lines will print out an array reference. I understand how to make it work, just curious about if there's something with hashes that makes them work a little differently? Thanks

Replies are listed 'Best First'.
Re: Multilayer dereferencing question
by Anonymous Monk on Mar 13, 2018 at 13:57 UTC
    Sorry I copied it over wrong, the print statement should be  print(@$$hash_s{'key'});
      @$$hash_s{key} is a shorter way of writing
      @{ ${ $hash_s } }{key}

      but you need

      @{ ${ $hash_s }{key} }

      which is usually written

      @{ $hash_s->{key} }
      as the arrow operator is more readable than the circumfix dereference.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

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

    No recent polls found