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

Hi Perlmonks I have a problem I was hoping you might be able to help me with. I have a file containing json data and I need to parse this using perl. I am using the perl module JSON::XS and I am able to decode this data and print the data structure using Data::Dumper. The problem I am having is that I want to be able to iterate over this data structure which is a hash of hashes and print out the all the key/value pairs and then ultimately be able to loop through this and print out particular key/value pairs. I have tried using the following hash_walk subroutine (Dave Hinton's) in http://stackoverflow.com/questions/2363142/how-to-iterate-through-hash-of-hashes-in-perl but this only prints out the values for the keys; dev, schema, and description. Please can you help me with what I need to do to print out all the key/values of the nested hashes? This is the data I am trying to parse

{ "schema":"Global Central Configuration file for dev", "description":"A representation of nfs mount points for dev machine +s", "tag":{ "dev":[ { "nfsmount":{ "home_nfs":{ "default":{ "opts":"nfsvers=3,timeo=600,retrans=2", "user":"root", "group":"root", "acl":"0755" }, "home-lnk-mpt":{ "export_name":"/links", "filer_device":{ "ny_loc":"nydevnfs_links", "nj_loc":"nydevnfs_links" }, "filer_volume":{ "ny_loc":"/vol/links", "nj_loc":"/vol/links" } }, "home7_mpt":{ "export_name":"/home7", "filer_device":{ "ny_loc":"nydevnfs_home7", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/home7", "nj_loc":"/vol/home7_c" } }, "home8_mpt":{ "export_name":"/home8", "filer_device":{ "ny_loc":"nydevnfs_home2", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/home2", "nj_loc":"/vol/home2_c" } }, "home9_mpt":{ "export_name":"/home9", "filer_device":{ "ny_loc":"nydevnfs_home1", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/home1", "nj_loc":"/vol/home1_c" } }, "home10_mpt":{ "export_name":"/home10", "filer_device":{ "ny_loc":"nydevnfs_home4", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/home4", "nj_loc":"/vol/home4_c" } }, "home11_mpt":{ "export_name":"/home11", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/home3", "nj_loc":"/vol/home3_c" } }, "home12_mpt":{ "export_name":"/home12", "filer_device":{ "ny_loc":"nydevnfs_home6", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/home6", "nj_loc":"/vol/home6_c" } }, "home13_mpt":{ "export_name":"/home13", "filer_device":{ "ny_loc":"nydevnfs_home5", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/home5", "nj_loc":"/vol/home5" } }, "home14_mpt":{ "export_name":"/home14", "filer_device":{ "ny_loc":"nydevnfs_home8", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/home8", "nj_loc":"/vol/home8_c" } }, "home15_mpt":{ "export_name":"/home15", "filer_device":{ "ny_loc":"nydevnfs_home9", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/home9", "nj_loc":"/vol/home9_c" } }, "home16_mpt":{ "export_name":"/home16", "filer_device":{ "ny_loc":"nydevnfs_home10", "nj_loc":"rnap7750-s" }, "filer_volume":{ "ny_loc":"/vol/home10", "nj_loc":"/vol/home10_c" } }, "home17_mpt":{ "export_name":"/home17", "filer_device":{ "ny_loc":"nydevnfs_home11", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/home11", "nj_loc":"/vol/home11_c" } }, "home18_mpt":{ "export_name":"/home18", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/home12", "nj_loc":"/vol/home12_c" } }, "home_tata_mpt":{ "export_name":"/home_tata", "filer_device":{ "ny_loc":"nydevnfs_tata_home", "nj_loc":null }, "filer_volume":{ "ny_loc":"/vol/tata_home", "nj_loc":null } } }, "mbig_nfs":{ "default":{ "opts":"nfsvers=3,timeo=600,retrans=2", "user":"root", "group":"root", "acl":"0755" }, "mbiga_mpt":{ "export_name":"/bb/mbiga", "filer_device":{ "ny_loc":"nnap7697-s", "nj_loc":"nydevnfs_mbiga" }, "filer_volume":{ "ny_loc":"/vol/mbiga", "nj_loc":"/vol/mbiga" } }, "mbigb_mpt":{ "export_name":"/bb/mbigb", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_mbigb" }, "filer_volume":{ "ny_loc":"/vol/mbigb", "nj_loc":"/vol/mbigb" } }, "mbigc_mpt":{ "export_name":"/bb/mbigc", "filer_device":{ "ny_loc":"nnap9412-s", "nj_loc":"nydevnfs_mbigc" }, "filer_volume":{ "ny_loc":"/vol/mbigc", "nj_loc":"/vol/mbigc" } }, "mbigd_mpt":{ "export_name":"/bb/mbigd", "filer_device":{ "ny_loc":"nnap9413-s", "nj_loc":"nydevnfs_mbigd" }, "filer_volume":{ "ny_loc":"/vol/mbigd", "nj_loc":"/vol/mbigd" } }, "mbigt_mpt":{ "export_name":"/bb/mbigt", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_mbigt" }, "filer_volume":{ "ny_loc":"/vol/mbigt", "nj_loc":"/vol/mbigt" } }, "mbig6_mpt":{ "export_name":"/bb/mbig6", "filer_device":{ "ny_loc":"nnap4211-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/mbig6", "nj_loc":"/vol/mbig6_c" } }, "mbig7_mpt":{ "export_name":"/bb/mbig7", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/mbig1", "nj_loc":"/vol/mbig1_c" } }, "mbig10_mpt":{ "export_name":"/bb/mbig10", "filer_device":{ "ny_loc":"nnap5166-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/mbig4", "nj_loc":"/vol/mbig4_c" } }, "mbig13_mpt":{ "export_name":"/bb/mbig13", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"rnap7750-s" }, "filer_volume":{ "ny_loc":"/vol/mbig8", "nj_loc":"/vol/mbig8_c" } }, "mbig14_mpt":{ "export_name":"/bb/mbig14", "filer_device":{ "ny_loc":"nnap5479-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/mbig9", "nj_loc":"/vol/mbig9_c" } }, "mbigold_mpt":{ "export_name":"/mbigold", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":null }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/mbig", "nj_loc":null } } }, "bigstor_nfs":{ "default":{ "opts":"nfsvers=3,timeo=600,retrans=2", "user":"root", "group":"root", "acl":"0755" }, "bigstor1_mpt":{ "export_name":"/bb/bigstor1", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor1", "nj_loc":"/vol/bigstor_volA/bigstor1" } }, "bigstor2_mpt":{ "export_name":"/bb/bigstor2", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor2", "nj_loc":"/vol/bigstor_volA/bigstor2" } }, "bigstor3_mpt":{ "export_name":"/bb/bigstor3", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor3", "nj_loc":"/vol/bigstor_volA/bigstor3" } }, "bigstor4_mpt":{ "export_name":"/bb/bigstor4", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor4", "nj_loc":"/vol/bigstor_volA/bigstor4" } }, "bigstor5_mpt":{ "export_name":"/bb/bigstor5", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor5", "nj_loc":"/vol/bigstor_volA/bigstor5" } }, "bigstor7_mpt":{ "export_name":"/bb/bigstor7", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor7", "nj_loc":"/vol/bigstor_volA/bigstor7" } }, "bigstor8_mpt":{ "export_name":"/bb/bigstor8", "filer_device":{ "ny_loc":"nydevnfs_bigstor_volA", "nj_loc":"nydevnfs_bigstor_volA" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volA/bigstor8", "nj_loc":"/vol/bigstor_volA/bigstor8" } }, "bigstor10_mpt":{ "export_name":"/bb/bigstor10", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor10", "nj_loc":"/vol/bigstor_volB/bigstor10" } }, "bigstor11_mpt":{ "export_name":"/bb/bigstor11", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor11", "nj_loc":"/vol/bigstor_volB/bigstor11" } }, "bigstor12_mpt":{ "export_name":"/bb/bigstor12", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor12", "nj_loc":"/vol/bigstor_volB/bigstor12" } }, "bigstor13_mpt":{ "export_name":"/bb/bigstor13", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor13", "nj_loc":"/vol/bigstor_volB/bigstor13" } }, "bigstor14_mpt":{ "export_name":"/bb/bigstor14", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor14", "nj_loc":"/vol/bigstor_volB/bigstor14" } }, "bigstor15_mpt":{ "export_name":"/bb/bigstor15", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor15", "nj_loc":"/vol/bigstor_volB/bigstor15" } }, "bigstor16_mpt":{ "export_name":"/bb/bigstor16", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor16", "nj_loc":"/vol/bigstor_volB/bigstor16" } }, "bigstor17_mpt":{ "export_name":"/bb/bigstor17", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volC" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volC/bigstor17", "nj_loc":"/vol/bigstor_volC/bigstor17" } }, "bigstor18_mpt":{ "export_name":"/bb/bigstor18", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volC" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volC/bigstor18", "nj_loc":"/vol/bigstor_volC/bigstor18" } }, "bigstor19_mpt":{ "export_name":"/bb/bigstor19", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volC" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volC/bigstor19", "nj_loc":"/vol/bigstor_volC/bigstor19" } }, "bigstor20_mpt":{ "export_name":"/bb/bigstor20", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volC" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volC/bigstor20", "nj_loc":"/vol/bigstor_volC/bigstor20" } }, "bigstor21_mpt":{ "export_name":"/bb/bigstor21", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volC" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volC/bigstor21", "nj_loc":"/vol/bigstor_volC/bigstor21" } }, "bigstor23_mpt":{ "export_name":"/bb/bigstor23", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volD" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volD/bigstor23", "nj_loc":"/vol/bigstor_volD/bigstor23" } }, "bigstor29_mpt":{ "export_name":"/bb/bigstor29", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor29", "nj_loc":"/vol/bigstor_volB/bigstor29" } }, "bigstor30_mpt":{ "export_name":"/bb/bigstor30", "filer_device":{ "ny_loc":"nnap5307-s", "nj_loc":"nydevnfs_bigstor_volB" }, "filer_volume":{ "ny_loc":"/vol/bigstor_volB/bigstor30", "nj_loc":"/vol/bigstor_volB/bigstor30" } }, "bigstorq0_mpt":{ "export_name":"/bb/bigstorq0", "filer_device":{ "ny_loc":"nydevnfs_bigstorq0", "nj_loc":"nydevnfs_bigstorq0" }, "filer_volume":{ "ny_loc":"/vol/bigstorq0", "nj_loc":"/vol/bigstorq0" } }, "bigstorq1_mpt":{ "export_name":"/bb/bigstorq1", "filer_device":{ "ny_loc":"nydevnfs_bigstorq1", "nj_loc":"nydevnfs_bigstorq1" }, "filer_volume":{ "ny_loc":"/vol/bigstorq1", "nj_loc":"/vol/bigstorq1" } }, "bigstorq2_mpt":{ "export_name":"/bb/bigstorq2", "filer_device":{ "ny_loc":"nydevnfs_bigstorq2", "nj_loc":"nydevnfs_bigstorq2" }, "filer_volume":{ "ny_loc":"/vol/bigstorq2", "nj_loc":"/vol/bigstorq2" } }, "bigstorq3_mpt":{ "export_name":"/bb/bigstorq3", "filer_device":{ "ny_loc":"nnap3289-s", "nj_loc":"nydevnfs_bigstorq3" }, "filer_volume":{ "ny_loc":"/vol/bigstorq3", "nj_loc":"/vol/bigstorq3" } }, "bigstorq4_mpt":{ "export_name":"/bb/bigstorq4", "filer_device":{ "ny_loc":"nnap3290-s", "nj_loc":"nydevnfs_bigstorq0" }, "filer_volume":{ "ny_loc":"/vol/bigstorq4", "nj_loc":"/vol/bigstorq4" } }, "bigstorqird_mpt":{ "export_name":"/bb/bigstor_ird", "filer_device":{ "ny_loc":"nnap3290-s", "nj_loc":"nydevnfs_bigstor_ird" }, "filer_volume":{ "ny_loc":"/vol/bigstor_ird", "nj_loc":"/vol/bigstor_ird" } }, "bigstorn_mpt":{ "export_name":"/bb/bigstorn", "filer_device":{ "ny_loc":"nydevnfs_bigstorn", "nj_loc":"nydevnfs_bigstorn" }, "filer_volume":{ "ny_loc":"/vol/bigstorn", "nj_loc":"/vol/bigstorn" } }, "bigstormtg_mpt":{ "export_name":"/bb/bigstor/mtgmodel", "filer_device":{ "ny_loc":"nydevnfs_mtge", "nj_loc":"njdevnfs_mtge" }, "filer_volume":{ "ny_loc":"/vol/mtge", "nj_loc":"/vol/mtge" } }, "bigstorderv_mpt":{ "export_name":"/bb/bigstor/derv", "filer_device":{ "ny_loc":"nydevnfs_derv", "nj_loc":"nydevnfs_derv" }, "filer_volume":{ "ny_loc":"/vol/mtge", "nj_loc":"/vol/mtge" } }, "bigstorsas_mpt":{ "export_name":"/bb/bigstor/sas", "filer_device":{ "ny_loc":"nydevnfs_sas", "nj_loc":"nydevnfs_sas" }, "filer_volume":{ "ny_loc":"/vol/sas", "nj_loc":"/vol/sas" } } }, "cc_nfs":{ "default":{ "opts":"nfsvers=3,timeo=600,retrans=2", "user":"root", "group":"root", "acl":"0755" }, "cc1_mpt":{ "export_name":"/cc/autoex", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_autoex" }, "filer_volume":{ "ny_loc":"/vol/autoex", "nj_loc":"/vol/autoex" } }, "cc2_mpt":{ "export_name":"/vol/default", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default" }, "filer_volume":{ "ny_loc":"/vol/default", "nj_loc":"/vol/default" } }, "cc3_mpt":{ "export_name":"/cc/defaulti", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_defaulti" }, "filer_volume":{ "ny_loc":"/vol/defaulti", "nj_loc":"/vol/defaulti" } }, "cc4_mpt":{ "export_name":"/cc/default2", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default2" }, "filer_volume":{ "ny_loc":"/vol/default2", "nj_loc":"/vol/default2" } }, "cc5_mpt":{ "export_name":"/cc/default3", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default3" }, "filer_volume":{ "ny_loc":"/vol/default3", "nj_loc":"/vol/default3" } }, "cc6_mpt":{ "export_name":"/cc/default4", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default4" }, "filer_volume":{ "ny_loc":"/vol/default4", "nj_loc":"/vol/default4" } }, "cc7_mpt":{ "export_name":"/cc/default5", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default5" }, "filer_volume":{ "ny_loc":"/vol/default5", "nj_loc":"/vol/default5" } }, "cc8_mpt":{ "export_name":"/cc/default6", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default6" }, "filer_volume":{ "ny_loc":"/vol/default6", "nj_loc":"/vol/default6" } }, "cc9_mpt":{ "export_name":"/cc/default7", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"nydevnfs_default7" }, "filer_volume":{ "ny_loc":"/vol/default7", "nj_loc":"/vol/default7" } }, "cc10_mpt":{ "export_name":"/cc/default8", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"nydevnfs_default8" }, "filer_volume":{ "ny_loc":"/vol/default8", "nj_loc":"/vol/default8" } }, "cc11_mpt":{ "export_name":"/cc/default9", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default9" }, "filer_volume":{ "ny_loc":"/vol/default9", "nj_loc":"/vol/default9" } }, "cc12_mpt":{ "export_name":"/cc/default10", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default10" }, "filer_volume":{ "ny_loc":"/vol/default10", "nj_loc":"/vol/default10" } }, "cc13_mpt":{ "export_name":"/cc/default11", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"nydevnfs_default11" }, "filer_volume":{ "ny_loc":"/vol/default11", "nj_loc":"/vol/default11" } }, "cc14_mpt":{ "export_name":"/cc/default12", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_default12" }, "filer_volume":{ "ny_loc":"/vol/default12", "nj_loc":"/vol/default12" } }, "cc15_mpt":{ "export_name":"/cc/default13", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_default13" }, "filer_volume":{ "ny_loc":"/vol/default13", "nj_loc":"/vol/default13" } }, "cc16_mpt":{ "export_name":"/cc/default14", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_default14" }, "filer_volume":{ "ny_loc":"/vol/default14", "nj_loc":"/vol/default14" } }, "cc17_mpt":{ "export_name":"/cc/default15", "filer_device":{ "ny_loc":"nnap7697-s", "nj_loc":"nydevnfs_default15" }, "filer_volume":{ "ny_loc":"/vol/default15", "nj_loc":"/vol/default15" } }, "cc18_mpt":{ "export_name":"/cc/default16", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_default16" }, "filer_volume":{ "ny_loc":"/vol/default16", "nj_loc":"/vol/default16" } }, "cc19_mpt":{ "export_name":"/cc/default17", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_default17" }, "filer_volume":{ "ny_loc":"/vol/default17", "nj_loc":"/vol/default17" } }, "cc20_mpt":{ "export_name":"/cc/default18", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_default18" }, "filer_volume":{ "ny_loc":"/vol/default18", "nj_loc":"/vol/default18" } }, "cc21_mpt":{ "export_name":"/cc/equity", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_equity" }, "filer_volume":{ "ny_loc":"/vol/equity", "nj_loc":"/vol/equity" } }, "cc22_mpt":{ "export_name":"/cc/fi", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_fi" }, "filer_volume":{ "ny_loc":"/vol/fi", "nj_loc":"/vol/fi" } }, "cc23_mpt":{ "export_name":"/cc/interface_tickers", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_inttkr" }, "filer_volume":{ "ny_loc":"/vol/inttkr", "nj_loc":"/vol/inttkr" } }, "cc24_mpt":{ "export_name":"/cc/interface_tickers2", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_inttkr2" }, "filer_volume":{ "ny_loc":"/vol/inttkr2", "nj_loc":"/vol/inttkr2" } }, "cc25_mpt":{ "export_name":"/cc/sw_inf", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_sw_inf" }, "filer_volume":{ "ny_loc":"/vol/sw_inf", "nj_loc":"/vol/sw_inf" } }, "cc26_mpt":{ "export_name":"/cc/sys_assurance", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_sys_assurance" }, "filer_volume":{ "ny_loc":"/vol/sys_assurance", "nj_loc":"/vol/sys_assurance" } }, "cc27_mpt":{ "export_name":"/cc/ts", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_ts" }, "filer_volume":{ "ny_loc":"/vol/ts", "nj_loc":"/vol/ts" } }, "cc28_mpt":{ "export_name":"/cc/vobs", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_vobs" }, "filer_volume":{ "ny_loc":"/vol/vobs", "nj_loc":"/vol/vobs" } }, "cc29_mpt":{ "export_name":"/bmds", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/bmds", "nj_loc":"/vol/bmds_c" } } }, "build_nfs":{ "default":{ "opts":"nfsvers=3,timeo=600,retrans=2", "user":"robocop", "group":"stage", "acl":"0775" }, "build1_mpt":{ "export_name":"/bpipebuild", "filer_device":{ "ny_loc":"nnap5479-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/bpipebuild", "nj_loc":"/vol/bpipebuild_c" } }, "build2_mpt":{ "export_name":"/bb/rapidbuild", "filer_device":{ "ny_loc":"nnap4586-ds", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/rapidbuild", "nj_loc":"/vol/rapidbuild_c" } }, "build3_mpt":{ "export_name":"/bbsrc_cg", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"rnap7750-s" }, "filer_volume":{ "ny_loc":"/vol/bbsrc_cg", "nj_loc":"/vol/bbsrc_cg_c" } }, "build4_mpt":{ "export_name":"/bbsrc", "filer_device":{ "ny_loc":"nnap5166-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/source", "nj_loc":"/vol/source_c" } }, "build5_mpt":{ "export_name":"/bbsrc2", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/source2", "nj_loc":"/vol/source2_c" } }, "build6_mpt":{ "export_name":"/bbsrc3", "filer_device":{ "ny_loc":"nnap4211-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/source3", "nj_loc":"/vol/source3_c" } }, "build7_mpt":{ "export_name":"/bbsrc4", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"rnap7750-s" }, "filer_volume":{ "ny_loc":"/vol/source4", "nj_loc":"/vol/source4_c" } }, "build8_mpt":{ "export_name":"/bbsrc_svn", "filer_device":{ "ny_loc":"nnap5479-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/srcctrl", "nj_loc":"/vol/srcctrl_c" } }, "build9_mpt":{ "export_name":"/bbshr", "filer_device":{ "ny_loc":"nnap5166-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/bbshr", "nj_loc":"/vol/bbshr_c" } }, "build10_mpt":{ "export_name":"/bb/source", "filer_device":{ "ny_loc":"nnap5479-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/sunbbsource", "nj_loc":"/vol/sunbbsource_c" } }, "build11_mpt":{ "export_name":"/bb/princeton", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_princetonsrc" }, "filer_volume":{ "ny_loc":"/vol/princetonsrc", "nj_loc":"/vol/princetonsrc" } }, "build12_mpt":{ "export_name":"/bb/system", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"nydevnfs_systemsrc" }, "filer_volume":{ "ny_loc":"/vol/systemsrc", "nj_loc":"/vol/systemsrc" } }, "build13_mpt":{ "export_name":"/bb/build/share", "filer_device":{ "ny_loc":"nnap5478-s", "nj_loc":"nydevnfs_build" }, "filer_volume":{ "ny_loc":"/vol/build", "nj_loc":"/vol/build" } }, "build14_mpt":{ "export_name":"/bb/cache", "filer_device":{ "ny_loc":"nydevnfs_pcache", "nj_loc":"nydevnfs_pcache" }, "filer_volume":{ "ny_loc":"/vol/pcache", "nj_loc":"/vol/pcache" } }, "build15_mpt":{ "export_name":"/bb/csbuild", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/csbuild2", "nj_loc":"/vol/csbuild2_c" } }, "build16_mpt":{ "export_name":"/bbsuid", "filer_device":{ "ny_loc":"nnap5166-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/bbsuid", "nj_loc":"/vol/bbsuid_c" } }, "build17_mpt":{ "export_name":"/bb/cstools", "filer_device":{ "ny_loc":"nnap5479-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/cstools", "nj_loc":"/vol/cstools_c" } }, "build18_mpt":{ "export_name":"/bb/mobile", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/mob_build", "nj_loc":"/vol/mob_build_c" } }, "build19_mpt":{ "export_name":"/bb/robostor", "filer_device":{ "ny_loc":"nydevnfs_robostor", "nj_loc":"nydevnfs_robostor" }, "filer_volume":{ "ny_loc":"/vol/robostor", "nj_loc":"/vol/robostor" } }, "build20_mpt":{ "export_name":"/bb/bbcm", "filer_device":{ "ny_loc":"nnap4210-s", "nj_loc":"nydevnfs_bbcm" }, "filer_volume":{ "ny_loc":"/vol/bbcm", "nj_loc":"/vol/bbcm" } }, "build21_mpt":{ "export_name":"/bb/stage", "filer_device":{ "ny_loc":"nnap5205-ds", "nj_loc":"nnap5205-ds" }, "filer_volume":{ "ny_loc":"/vol/stage", "nj_loc":"/vol/stage" } }, "build22_mpt":{ "export_name":"/bb/client_sdk", "filer_device":{ "ny_loc":"nnap4211-s", "nj_loc":"rnap7751-s" }, "filer_volume":{ "ny_loc":"/vol/csdk", "nj_loc":"/vol/csdk_c" } }, "build23_mpt":{ "export_name":"/bb/unsupported", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/uleq", "nj_loc":"/vol/uleq_c" } }, "build24_mpt":{ "export_name":"/bb/offlines", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/offlines1", "nj_loc":"/vol/offlines1_c" } }, "build25_mpt":{ "export_name":"/bb/fesrc", "filer_device":{ "ny_loc":"nnap5165-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/fesrc", "nj_loc":"/vol/fesrc_c" } }, "build26_mpt":{ "export_name":"/bb/build/SunOS-sparc-32", "filer_device":{ "ny_loc":"nnap7698-s", "nj_loc":"rnap2114-s" }, "filer_volume":{ "ny_loc":"/vol/bldsparc32", "nj_loc":"/vol/bldsparc32_c" } }, "build27_mpt":{ "export_name":"/bb/build/SunOS-sparc-64", "filer_device":{ "ny_loc":"nnap7697-s", "nj_loc":"rnap2113-s" }, "filer_volume":{ "ny_loc":"/vol/bldsparc64", "nj_loc":"/vol/bldsparc64_c" } }, "build28_mpt":{ "export_name":"/bb/binrobo", "filer_device":{ "ny_loc":"nnap5308-s", "nj_loc":"nnap5308-s" }, "filer_volume":{ "ny_loc":"/vol/binrobo/sun", "nj_loc":"/vol/binrobo/sun" } } } } } ] } }

Replies are listed 'Best First'.
Re: Iterate over a perl nested hash data structure
by nvivek (Vicar) on Feb 20, 2013 at 07:00 UTC

    In perl, if we want to get the key/value pairs of hash, you can use the following code.

    use strict; use warnings; # initializing hash with three four-value pairs, among those two are h +aving inner hashes ( Numerals, Alpha ) which have three key-value pai +rs in-built my %hash = ( 'Numerals' => { '1' => 'One', '2' => 'Two', '3' => 'Three', }, 'Alpha' => { 'A' => 'Apple', 'B' => 'Ball', 'C' => 'Cat' }, 'I' => 'Roman One', 'II' => 'Roman Two' );<br/> # for getting key-value pairs of above hash foreach(keys%$hash) { # by default key stored in $_ as per above foreach statement # checks whether value of hash is another hash if(ref($hash{$_}) eq 'HASH') { # iterate the keys set of inner hash foreach my $inner_key (keys%{$hash{$_}}) { # printing key and value of inner hash print "Key:$inner_key and value:$hash{$_}{$inner_key}\n"; } } else { print "Key: $_ and Value: $hash{$_}\n" } }
      Thanks ever so much for your help :-) I will try this out

        Sorry guys I still can't get this working. I all tried all the examples. This is a small sample of the data that is dumped via data::dumper

        $VAR1 = 'tag'; $VAR2 = { 'dev' => [ { 'nfsmount' => { 'bigstor_nfs' => {

        I am putting all of this data into a hash but when I print the keys in the hash all I can print out is 'dev' and 'tag'. I want to get past the point where the right [ bracket is (which is array called 'dev'). Below 'nfsmount' I have about 50 different hashes defined, one of which is called 'bigstor_nfs'. I want to be able to search through all the available hashes and depending on what the name of the hash is I then want print out all the key/values contained within each hash and output this to another file.

Re: Iterate over a perl nested hash data structure
by BrowserUk (Patriarch) on Feb 20, 2013 at 05:49 UTC
    I am able to decode this data and print the data structure using Data::Dumper. The problem I am having is that I want to be able to iterate over this data structure which is a hash of hashes and print out the all the key/value pairs

    You say you can data Dump the structure; and then say you want to print everything out; which is exactly what Data::Dumper does.

    So, what do you want to do different to the way Data::Dumper does it?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Sorry I didn't explain myself properly. I want to be able to iterate through the nested hashes and and depending on what the name of one of the hashes is I want to then print out all the key/value pairs in that particular hash and then output this data to another file

        I want to be able to iterate through the nested hashes and and depending on what the name of one of the hashes is I want to then print out all the key/value pairs in that particular hash

        You don't need to "iterate" over a hash to find a particular value (subhash), you can go straight to it. That is the whole point of hashes.

        If you know the path to the hash you want to print, you can go straight there.

        Eg. To dump the key/value pairs in the hash at $HoHoH{ C }{ 2 }:

        #! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 100; my %HoHoH = map{ my $l1 = $_; $l1 => { map{ my $l2 = $_; $l2 => { map{ $_ => "$l1 $l2 $_" } 'a'..'d' } } 0 .. 4 }; } 'a'..'d'; pp \%HoHoH; ## print "key:$_ val: $HoHoH{ c }{ 2 }{ $_ }" for keys %{ $HoHoH{ c }{ 2 + } }; __END__ C:\test>junk30 { a => { "0" => { a => "a 0 a", b => "a 0 b", c => "a 0 c", d => "a 0 +d" }, 1 => { a => "a 1 a", b => "a 1 b", c => "a 1 c", d => "a 1 +d" }, 2 => { a => "a 2 a", b => "a 2 b", c => "a 2 c", d => "a 2 +d" }, 3 => { a => "a 3 a", b => "a 3 b", c => "a 3 c", d => "a 3 +d" }, 4 => { a => "a 4 a", b => "a 4 b", c => "a 4 c", d => "a 4 +d" }, }, b => { "0" => { a => "b 0 a", b => "b 0 b", c => "b 0 c", d => "b 0 +d" }, 1 => { a => "b 1 a", b => "b 1 b", c => "b 1 c", d => "b 1 +d" }, 2 => { a => "b 2 a", b => "b 2 b", c => "b 2 c", d => "b 2 +d" }, 3 => { a => "b 3 a", b => "b 3 b", c => "b 3 c", d => "b 3 +d" }, 4 => { a => "b 4 a", b => "b 4 b", c => "b 4 c", d => "b 4 +d" }, }, c => { "0" => { a => "c 0 a", b => "c 0 b", c => "c 0 c", d => "c 0 +d" }, 1 => { a => "c 1 a", b => "c 1 b", c => "c 1 c", d => "c 1 +d" }, 2 => { a => "c 2 a", b => "c 2 b", c => "c 2 c", d => "c 2 +d" }, 3 => { a => "c 3 a", b => "c 3 b", c => "c 3 c", d => "c 3 +d" }, 4 => { a => "c 4 a", b => "c 4 b", c => "c 4 c", d => "c 4 +d" }, }, d => { "0" => { a => "d 0 a", b => "d 0 b", c => "d 0 c", d => "d 0 +d" }, 1 => { a => "d 1 a", b => "d 1 b", c => "d 1 c", d => "d 1 +d" }, 2 => { a => "d 2 a", b => "d 2 b", c => "d 2 c", d => "d 2 +d" }, 3 => { a => "d 3 a", b => "d 3 b", c => "d 3 c", d => "d 3 +d" }, 4 => { a => "d 4 a", b => "d 4 b", c => "d 4 c", d => "d 4 +d" }, }, } key:c val: c 2 c key:a val: c 2 a key:b val: c 2 b key:d val: c 2 d

        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      This is what data::dumper prints out. I want to be able to iterate over this. So for example if $VAR2 = 'dev', then read 'nfsmount' and then depending on whether the next level down equals 'bigstor_nfs'/'mbig_nfs'/'build_nfs'/'cc_nfs'/'home_nfs' I want to then be able to iterate over those individual hashes and extract particular key/value pairs and output to another file:
      $VAR1 = 'tag'; $VAR2 = { 'dev' => [ { 'nfsmount' => { 'bigstor_nfs' => { 'bigstor17_m +pt' => { + 'filer_device' => { + 'ny_loc' => 'nnap5307-s', + 'nj_loc' => 'nydevnfs_bigstor_volC' + }, + 'filer_volume' => { + 'ny_loc' => '/vol/bigstor_volC/bigstor17 +', + 'nj_loc' => '/vol/bigstor_volC/bigstor17 +' + }, + 'export_name' => '/bb/bigstor17' + },
Re: Iterate over a perl nested hash data structure
by tmharish (Friar) on Feb 20, 2013 at 06:19 UTC

      Yes. I am using JSON::XS to decode the json data. Then when I dump this with data::dumper to see what it looks like it is a hash of hashes. I am struggling with how to iterate over each of the individual hashes and depending on what the name of these are I want to then print out the key/value pairs within that hash

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Iterate over a perl nested hash data structure
by Anonymous Monk on Feb 20, 2013 at 08:04 UTC
    use Data::Diver qw( Dive ); my $nj_loc = Dive( $root, qw[ dev 0 nfsmount bigstor_nfs bigstor17_m +pt filer_device nj_loc ] );

    JSON::Path

Re: Iterate over a perl nested hash data structure
by aitap (Curate) on Feb 20, 2013 at 13:55 UTC
    All you need is love Data::Dumper (pointed out above) and perlreftut, it contains the neseccary instructions for building and accessing multi-level data structures.
    Sorry if my advice was wrong.

      So for instance I want to read the hash and do something like this. If find hash called 'bigstor_nfs' then print out to another file all the key/value pairs. then carry on to the next hash name at this level in the data structure. If thats called 'test_nfs' then print out all the key/values pairs to the same output file and then continue doing this comparing the names of each hash until the end of the data structure I think this is possible. I have tried so may different ways and I cant get this to work. Please can you help me?

        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.