Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Multilayer dereferencing question

by Anonymous Monk
on Mar 13, 2018 at 13:53 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1210822]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-06-18 23:25 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.