in reply to Re^5: Setting up conditional check for printing out keys from array/hash ref
in thread Setting up conditional check for printing out keys from array/hash ref
Thanks Grandfather. I did what you said and copied the dump output and added it to your code. It worked. What might be the problem is my config for using XML::Simple for reading the xml?
Here is the setting for XML::SimpleHere is the additional hash output.my $data = $xml->XMLin(`$lsCmd`, ForceArray => 1);
my $lsResults3 = { 'recursive' => 'no', 'version' => '0.20.202.1.1101050227', 'time' => '2011-10-28T20:54:09+0000', 'filter' => '.*', 'path' => '/', 'directory' => [ { 'owner' => 'hdfs', 'group' => 'hdfs', 'permission' => 'drwxr-xr-x', 'path' => '/', 'accesstime' => '1970-01-01T00:00:00+0000', 'modified' => '2011-10-06T19:30:33+0000' }, { 'owner' => 'xyz', 'group' => 'hdfs', 'permission' => 'drwx------', 'path' => '/A29', 'accesstime' => '1970-01-01T00:00:00+0000', 'modified' => '2011-10-06T19:30:38+0000' }, { 'owner' => 'rawk', 'group' => 'hdfs', 'permission' => 'drwx------', 'path' => '/B29TABTV001', 'accesstime' => '1970-01-01T00:00:00+0000', 'modified' => '2011-02-08T22:24:15+0000' }, { 'owner' => 'xyz', 'group' => 'hdfs', 'permission' => 'drwx------', 'path' => '/FOOBAR', 'accesstime' => '1970-01-01T00:00:00+0000', 'modified' => '2010-10-04T10:44:17+0000' }, { 'owner' => 'xyz', 'group' => 'hdfs', 'permission' => 'drwxr-xr-x', 'path' => '/data', 'accesstime' => '1970-01-01T00:00:00+0000', 'modified' => '2011-08-25T07:56:15+0000' }, { 'owner' => 'hdfs', 'group' => 'hdfs', 'permission' => 'drwxr-xr-x', 'path' => '/user', 'accesstime' => '1970-01-01T00:00:00+0000', 'modified' => '2011-10-25T04:21:55+0000' } ], 'exclude' => '' }; for my $result ($lsResults1, $lsResults2, $lsResults3) { for (keys %$result) { if ($_ eq 'file') { print "Filename: $result->{file}{path}\n"; print " Size: $result->{file}{size}\n"; } elsif ($_ eq 'directory') { my $value = ref $result->{directory}; if ($value eq 'ARRAY') { for my $entry (@{$result->{directory}}) { print "Directory: $entry->{path}\n"; } } elsif ($value eq 'HASH') { print "Directory: $result->{directory}{path}\n"; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Setting up conditional check for printing out keys from array/hash ref
by GrandFather (Saint) on Oct 28, 2011 at 23:04 UTC |