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

Re^3: Iterate over a perl nested hash data structure

by aitap (Deacon)
on Feb 20, 2013 at 16:17 UTC ( #1019804=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Iterate over a perl nested hash data structure
in thread Iterate over a perl nested hash data structure

As far as I understand the JSON syntax, your document contains only one array (under 'dev' key) which consists of only one hash (with only one key called 'nfsmount'). All other data structures are hashes, which only allow unique key names.

Thus, you need to print only two hash keys and there is no need in manual listing of all keys in this document. Try this:

use JSON; use Data::Dumper; ...; # open files, read the JSON string my $data = decode_json $your_json_string; for (qw/bigstor_nfs test_nfs/) { # list of keys to search for print {$filehandle} Dumper { $_ => $data->{tag}{dev}[0]{nfsmount}{$_} + } if exists $data->{tag}{dev}[0]{nfsmount}{$_}; # print to prevousely opened filehandle: # the results of "dumping" of anonymous hash reference # containing the key and its value # if this key exists in the main hash }

Sorry if my advice was wrong.


Comment on Re^3: Iterate over a perl nested hash data structure
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-09-23 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls