Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: nested hashes and their usage e.g $foo{bar}{baz}

by crouchingpenguin (Priest)
on Feb 26, 2003 at 17:13 UTC ( [id://238847]=note: print w/replies, xml ) Need Help??


in reply to nested hashes and their usage e.g $foo{bar}{baz}

This situation is where I would usually use Data::Dumper to help show the entire data structure:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; + my %srciphash = ( '10.10.10.1' => { '10.10.10.2' => 'gw', '10.10.10.3' => 'dns', '10.10.10.4' => 'www', }, '10.10.20.1' => { '10.10.20.2' => 'gw', '10.10.20.3' => 'dns', '10.10.20.4' => 'www', }, ); + foreach my $a ( keys %srciphash ){ foreach my $b ( keys %{$srciphash{$a}} ){ #print $b,"\t",$srciphash{$a}{$b},"\n"; } } + print Dumper(\%srciphash),"\n";

outputs
$VAR1 = { '10.10.20.1' => { '10.10.20.4' => 'www', '10.10.20.3' => 'dns', '10.10.20.2' => 'gw' }, '10.10.10.1' => { '10.10.10.2' => 'gw', '10.10.10.4' => 'www', '10.10.10.3' => 'dns' } };

cp
---
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found