Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Debugger: I must be missing something

by sfink (Deacon)
on Dec 11, 2006 at 18:19 UTC ( [id://589108]=note: print w/replies, xml ) Need Help??


in reply to Debugger: I must be missing something

Taming the printing of @_

Do it in stages. Avoid 'x' as long as you need to if there's a possibility of an enormous data structure:

<DB> p "@_" ARRAY(0x38234) Big::Nested::Mess=HASH(0x382437) <DB> x keys %{ $_[1] } ...just the keys, so you can see what to look for...
When I was doing this a lot, I defined a p() subroutine that made a recursive copy of complex data structures, only the copy was something much more readable. This is assuming that the big nasty data structure is your own, and you have some application-specific notion of what would be more or less interesting to see in the output.
sub p { my $x = shift; if (! ref $x) { return $x; } elsif (ref($x) eq 'My::Class') { return bless { name => $x->{name}, manager => $x->{manager}->getId(), children => p($x->{children}), # add any other fields you want to see }, ref($x); } elsif (UNIVERSAL::isa($x, 'ARRAY')) { return [ map { p($_) } @$x ]; } elsif (UNIVERSAL::isa($x, 'HASH')) { return { map { $_ => p($x->{$_}) } keys %$x }; } else { return $x; } }
...tailored to your specific situation. (Actually, I think I also did a UNIVERSAL::can($x, 'p') to see if the object implemented its own readable-conversion method.)

Then you can do 'x p($whatever)' and get your customized dump. (You can take this farther, and pass in a "brevity level" parameter that starts out zero to display everything, but increases as you get into further nested things so that they will display as one-line summaries rather than structural dumps.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://589108]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found