Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Printing slice of anonymous hash within hash

by nysus (Parson)
on Jul 05, 2001 at 11:17 UTC ( [id://94028]=perlquestion: print w/replies, xml ) Need Help??

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'};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found