in reply to Re^4: 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

The sample code I provided is fewer than 100 lines including the sample hash initialisation. That is less than the line containing the error according to your error message so I can't easily tell where the error is happening. Perhaps you'd like to modify the data in my sample code to reproduce the error then post that?

True laziness is hard work
  • Comment on Re^5: Setting up conditional check for printing out keys from array/hash ref

Replies are listed 'Best First'.
Re^6: Setting up conditional check for printing out keys from array/hash ref
by JaeDre619 (Acolyte) on Oct 28, 2011 at 21:22 UTC

    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"; } } } }

      I'd avoid XML::Simple. Use XML::Twig instead. XML::Twig looks more complicated (and is), but it's often easier to get right! The problem is that XML::Simple makes guesses about sensible defaults for handling XML files that are fine for a small number of simple applications such as configuration files (where it works very well), but are just plain broken for many tasks. And when stuff breaks with XML::Simple it's often hard to figure out why. Note that it is XML::Simple, not XML::Easy!

      True laziness is hard work