That just changes the amount of whitespace. Here is an example of
what I want:
Some::Package {
a => 'a value',
b => 12,
c => Other::Package {
x => 34
}
}
instead of what Data::Dumper gives me, which seems to be:
p is $VAR1 = bless( [
bless( {
'c' => 3,
'a' => 1,
'b' => 2,
}, 'pseudohash' ),
'a value',
12,
bless( [
bless( {
'x' => 1
... you get the picture. The output is so complicated that I have a
hard time seeing what's wrong with my application code ...
I tried to do it "manually" with an "objectToString" method, but
somehow there seem to be weird cases of data layout that I can't
quite get my head around without spending a lot of time on it. I
figure somebody must have wanted this before? But Google is of no
help ...
On Feb 23, 2006, at 19:44, Octavian Rasnita wrote:
From: "Johannes Ernst" <[EMAIL PROTECTED]>
PHP knows print_r -- which prints a data structure hierarchically,
and is very useful for debugging.
e.g.
echo "Variable a is " . print_r( $a, true ) . "\n";
Is there something similarly easy in Perl?
It appears that Data::Dumper may be of help, but I have not been able
to figure out how to make the output reasonably compact (I don't want
to see the pseudo-hash index fields etc.)
Have you read: ?
perldoc Data::Dumper
Maybe this is what you need:
* $Data::Dumper::Indent *or* *$OBJ*->Indent(*[NEWVAL]*)
Controls the style of indentation. It can be set to 0, 1, 2
or 3.
Style 0 spews output without any newlines, indentation, or
spaces
between list items. It is the most compact format possible
that can
still be called valid perl. Style 1 outputs a readable form
with
newlines but no fancy indentation (each level in the
structure is
simply indented by a fixed amount of whitespace). Style 2 (the
default) outputs a very readable form which takes into
account the
length of hash keys (so the hash value lines up). Style 3
is like
style 2, but also annotates the elements of arrays with
their index
(but the comment is on its own line, so array output
consumes twice
the number of lines). Style 2 is the default.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>