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"; } } } }
In reply to Re^3: Setting up conditional check for printing out keys from array/hash ref
by GrandFather
in thread Setting up conditional check for printing out keys from array/hash ref
by JaeDre619
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |