chimiXchanga has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking to alter the output, the way Data::Dumper prints it out. Any help on that? Thank you!sub dumpomatic { my ($obj) = @_; if (ref($obj) eq 'ARRAY') { print "[ "; for my $index (0.. $#$obj) { dumpomatic($obj->[$index]); print ", " if $index < $#$obj; } print " ]"; } elsif (ref($obj) eq 'HASH') { my @keys = sort keys %$obj; print "{ "; for my $index (0.. $#keys) { print "$keys[$index] => "; dumpomatic($obj->{$keys[$index]}); print ", " if $index < $#keys; } print " }"; } elsif (ref($obj) eq 'SCALAR') { print $$obj; } else { print $obj; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Beautiful recursive print
by Corion (Patriarch) on Mar 17, 2017 at 09:44 UTC | |
by chimiXchanga (Novice) on Mar 17, 2017 at 11:48 UTC | |
|
Re: Beautiful recursive print
by huck (Prior) on Mar 17, 2017 at 10:16 UTC | |
by BillKSmith (Monsignor) on Mar 17, 2017 at 14:17 UTC | |
by choroba (Cardinal) on Mar 20, 2017 at 09:04 UTC | |
|
Re: Beautiful recursive print
by Eily (Monsignor) on Mar 17, 2017 at 10:37 UTC |