in reply to each on reference is experimental take 2
Sounds like you might want to study perldsc a bit. As the other monks have already explained, the best and most compatible way to dereference the hashref is to use each %{ ... }.
The "push/pop/splice/each on reference" feature (aka "autoderef") will be gone in Perl v5.24, so your first bit of code will only work (with a warning) on Perls v5.14 thru v5.22.
As a possible replacement, the feature "Postfix Dereference Syntax" introduced in v5.20 will hopefully be pulled out of experimental status eventually:
#!/usr/bin/env perl use warnings; use 5.020; use feature 'postderef'; no warnings 'experimental::postderef'; my %hoh = ( foo=>{a=>1,b=>2}, bar=>{c=>3,d=>4} ); for my $name (keys %hoh) { while ( my ($key,$value) = each $hoh{$name}->%* ) { say "$key: $value"; } }
Unfortunately, since this feature is experimental too, there is no guarantee that it won't be removed as well. But this one does seem more likely to stay at the moment. I'm not sure if a decision has been made as to when it might come out of expiermental state.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: each on reference is experimental take 2
by Anonymous Monk on Mar 10, 2016 at 21:15 UTC |