in reply to Beautiful recursive print
What part of the output as Data::Dumper creates it are you missing?
If you want to nicely indent your code, pass the level as a second parameter to your routine when it recurses, and indent according to level:
sub dumpomatic { my( $obj, $level ) = @_; $level ||= 0; my $prefix = " " x $level; ... print $prefix. "["; ... print $prefix. "{"; ... print $prefix. $$obj; ... print $prefix. $obj;
Also, you might want to recurse once more in the ref($obj) eq 'SCALAR' case, and not print $$obj but '\\' and then dumpomatic($$obj).
This would also handle pathologic cases like
my $ar = ['pirate', 'ninja']; my $arr = \$ar; my $arrr = \$arr; dumpomatic( $arrr );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Beautiful recursive print
by chimiXchanga (Novice) on Mar 17, 2017 at 11:48 UTC |