jhanna has asked for the wisdom of the Perl Monks concerning the following question:
For discussion sake, let's assume all blessed objects are hashes. Does that help?# NOTE: THIS IS BUSTED, but interesting... sub DDumper { my($v,$i)=@_; # v=what we're dumping, i=indent $i="\n" unless $i; $i.=' '; my $r=ref($v); my $s=''; # s is the string we'll return when done if($r eq HASH) { $s.= "{ "; for (keys %$v) { $s.= Dumper($_,$i)." => ".Dumper($v->{$_},$i).",$i"; } $s.= " }$i"; } elsif($r eq ARRAY) { $s.= "[ "; for ( @$v) { $s.= Dumper($_,$i).",$i"; } $s.= " ]$i"; } elsif($r) { $s.= "bless( ".Dumper(%{$v},$i).", '$r') $i"; } else { $s.= "'$v' "; } $s; }
This snippit recurses endlessly on blessed objects (I think) and has the curious property of doubling square brackets and doing goofy things with quotes and commas in hashes.
Well, it was an interesting recursive diversion...
j
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Data::Dumper in perl-only?
by PrakashK (Pilgrim) on Jan 24, 2002 at 03:46 UTC | |
by jhanna (Scribe) on Jan 24, 2002 at 04:03 UTC | |
|
Re: Data::Dumper in perl-only?
by FoxtrotUniform (Prior) on Jan 24, 2002 at 03:12 UTC | |
|
Re: Data::Dumper in perl-only?
by perrin (Chancellor) on Jan 24, 2002 at 03:40 UTC | |
|
Re: Data::Dumper in perl-only?
by theorbtwo (Prior) on Jan 24, 2002 at 05:59 UTC | |
by jhanna (Scribe) on Jan 24, 2002 at 09:12 UTC | |
by demerphq (Chancellor) on Jan 24, 2002 at 14:43 UTC | |
by jhanna (Scribe) on Jan 25, 2002 at 03:06 UTC |