in reply to How can i debug compound map/grep statements just using print?
please, next time post clear questions with isolated code examples.
map and grep use code blocks which depend on the return value of the last statement.
that means you can use the same techniques used for debugging subroutines, e.g. you can use print anywhere within these blocks, as long as it doesn't change the returned value.
you can also split deeply nested maps and greps in smaller chunks filling temporary arrays and dump these results with Data::Dumper.
UPDATE:
and if you really need it very often, use something which assures the same list as in- and output
sub dumplist { use Data::Dumper; print Dumper \@_; return @_; } @result= map { ... } dumplist grep { ... } @input;
example:
@evenchars = map { $_->[0] } dumplist grep { $_->[1] % 2 } map { [ $_, ord($_) ] } a..l; #prints $VAR1 = [ [ 'a', 97 ], [ 'c', 99 ], [ 'e', 101 ], [ 'g', 103 ], [ 'i', 105 ], [ 'k', 107 ] ];
Cheers Rolf
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How can i debug compound map/grep statements just using print?
by karlgoethebier (Abbot) on Dec 01, 2012 at 19:29 UTC | |
by LanX (Saint) on Dec 01, 2012 at 19:36 UTC | |
| |
by space_monk (Chaplain) on Dec 02, 2012 at 09:02 UTC | |
by karlgoethebier (Abbot) on Dec 02, 2012 at 10:55 UTC |
In Section
Seekers of Perl Wisdom