Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^8: Syntax for casting map to a hash or an array

by cbeckley (Curate)
on Apr 05, 2017 at 19:14 UTC ( #1187176=note: print w/replies, xml ) Need Help??


in reply to Re^7: Syntax for casting map to a hash or an array
in thread Syntax for casting map to a hash or an array

Ugh, right, that was a typo. I was trying to compare these two lines.

say Dumper(\%{ {map { $_ => 'fish' } qw(one two red blue)} } ); say Dumper({map { $_ => 'fish' } qw(one two red blue)});

Thank you for the correction.

Thanks,
cbeckley

Replies are listed 'Best First'.
Re^9: Syntax for casting map to a hash or an array
by shmem (Chancellor) on Apr 05, 2017 at 19:28 UTC

    Yes, these two are exactly the same, except for one gratitous reference-dereference round trip.

    If you dereference a reference and take a reference to the dereferenced reference, this reference will be the same as the original reference.

    #!/usr/bin/perl -l $h = {map { $_ => 'fish' } qw(one two red blue)}; print $h; print \%{$h}; print \%{\%{$h}}; print \%{\%{\%{$h}}}; print \%{\%{\%{\%{$h}}}}; print \%{\%{\%{\%{\%{$h}}}}}; print \%{\%{\%{\%{\%{\%{$h}}}}}}; print \%{\%{\%{\%{\%{\%{\%{$h}}}}}}}; print \%{\%{\%{\%{\%{\%{\%{\%{$h}}}}}}}}; __END__ HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548) HASH(0x17ea548)

    Sorry for so may ref-deref, couldn't stop... %-)

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      "If you dereference a reference and take a reference to the dereferenced reference, this reference will be the same as the original reference."

      LOL :) It took me a lot of years coding Perl before I would have been able to understand exactly what's being said there. If one can grasp that, along with the actual syntax to do it, one can do anything.

      It was my bad originally to claim they both work for different reasons. *That* was kind of a typo as well. I was thinking too far ahead at the time ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-05-28 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (166 votes). Check out past polls.

    Notices?