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

Slices of anonymous data structures within hashes/array are still kicking my butt. This time I've got an anonymous hash within a hash and I'm wondering how to print out a slice of the anonymous hash like so:
print @visits{$key}->{'ip', 'last_time'}; # this doesn't work print @visits{$key}{'ip', 'last_time'}; # nor this Out of desperation, I've also tried: %$visits{$key}{'ip', 'last_time'} %@visits{$key}{'ip', 'last_time'} @@visits{$key}{'ip', 'last_time'} @$visits{$key}{'ip', 'last_time'} ...and the above with an infix operator.
As always, any help for my sorry a** is greatly apprciated. Thanks!

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: Printing slice of anonymous hash within hash
by ariels (Curate) on Jul 05, 2001 at 11:25 UTC
    Your problem is that (syntactically speaking) your slice happens before you get a chance to dereference.

    Try adding braces, like this:

    %x = ( abc => { ip => v1.2.3.4, last_time => 'today' }, def => { ip => v5.6.7.8, last_time => 'yesterday ' }, ); @y = @{$x{def}}{'last_time', 'ip'};
Re: Printing slice of anonymous hash within hash
by btrott (Parson) on Jul 05, 2001 at 11:23 UTC
    @{ $visits{$key} }{'ip', 'last_time'};