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::Simple
my $data = $xml->XMLin(`$lsCmd`, ForceArray => 1);
Here is the additional hash output.
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"; } } } }

In reply to Re^6: Setting up conditional check for printing out keys from array/hash ref by JaeDre619
in thread Setting up conditional check for printing out keys from array/hash ref by JaeDre619

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.