http://www.perlmonks.org?node_id=1006623


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