Now I got the following output:
%mount_acl = 0755 %mount_group = root %mount_opts = nfsvers=3,timeo=600,retrans=2 %export_name = /links %export_name = /home7 %export_name = /home8
apparently most elements you wanted, just in different lines because you finished your prints with "\n".
IMHO you still need to store the defaults and print them if there are no other details for a path.
Here my code. this should give you a start to continue:
use strict; use warnings; use Data::Dump qw/pp/; my $nfs ={ '%name'=> 'Global Central Configuration file', '%description'=> 'A representation of nfs mount points for d +ev machines', '%schema'=> 'schema.conf', '@dev'=> { 'home_nfs'=> { '%default'=> { '%mount_opts'=> 'nfsve +rs=3,timeo=600,retrans=2', '%mount_user'=> 'root' +, '%mount_group'=> 'root +', '%mount_acl'=> '0755' }, '%comment'=> '----Home NFS Directori +es----', 'home-lnk-mpt'=> { '%export_name'=> ' +/links', '%filer_device'=> +{ + '@west'=> 'nydevnfs_links', + '@ridge'=> 'rnap7750-s' +}, '%filer_volume'=> +{ + '@west'=> '/vol/links', + '@ridge'=> '/vol/links_c' +} }, 'home7_mpt'=> { '%export_name'=> '/ho +me7', '%filer_device'=> { '@ +west'=> 'nydevnfs_home7', '@ +ridge'=> 'rnap7751-s' }, '%filer_volume'=> { '@ +west'=> '/vol/home7', '@ +ridge'=> '/vol/home7_c' } }, 'home8_mpt'=> { '%export_name'=> '/ho +me8', '%filer_device'=> { '@ +west'=> 'nydevnfs_home2', '@ +ridge'=> 'rnap2114-s' }, '%filer_volume'=> { '@ +west'=> '/vol/home2', '@ +ridge'=> '/vol/home2_c' } }, } } }; my @keylist=('%export_name','%filer_device','%filer_volume','%mount_ac +l','%mount_group','%mount_opts'); recurse_hash($nfs,@keylist); sub recurse_hash { my($hash,@findkeys) = @_; foreach (sort keys %{$hash}) { my $value = $hash->{$_}; if (ref($value) eq 'HASH') { recurse_hash($value,@findkeys); } else { for my $key (@findkeys) { if ($key eq $_) { print "$_ = $value\n"; } } } } }
Cheers Rolf
( addicted to the Perl Programming Language)
In reply to Re: Traversing a complex data structure searching for certain keys and printing their values
by LanX
in thread Traversing a complex data structure searching for certain keys and printing their values
by newperluser2013
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |