in reply to Re^2: 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 solution I offered is not in itself recursive, although it could be the guts of a recursive solution.
given/when is Perl's switch statement support which was introduced with 5.10. A switch statement is really just syntactic sugar for a set of related if statements so you can replace the when blocks with if blocks:
for my $result ($lsResults1, $lsResults2) { 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^4: Setting up conditional check for printing out keys from array/hash ref
by JaeDre619 (Acolyte) on Oct 27, 2011 at 23:41 UTC | |
by GrandFather (Saint) on Oct 28, 2011 at 07:30 UTC | |
by JaeDre619 (Acolyte) on Oct 28, 2011 at 21:22 UTC | |
by GrandFather (Saint) on Oct 28, 2011 at 23:04 UTC |