in reply to Re^2: foreach - adding newlines?
in thread foreach - adding newlines?

Try this instead:

{ use Data::Dumper; print(Data::Dumper->new( [ $,, $", $\, $/, \@EVENT_ARRAY, \@array, ], [qw( $, $" $\ $/ $EVENT_ARRAY $array )] )->Useqq(1)->Dump()); }

Update: (cf. johngg's reply) I suggested to move the parameters from Dump() to new() — otherwise I left ikegami's code as is. For reference, the original code was:

{ use Data::Dumper; print(Data::Dumper->new()->Useqq(1)->Dump( [ $,, $", $\, $/, \@EVENT_ARRAY, \@array, ], [qw( $, $" $\ $/ $EVENT_ARRAY $array )] )); }

Replies are listed 'Best First'.
Re^4: foreach - adding newlines?
by johngg (Canon) on Feb 09, 2009 at 23:09 UTC

    You can use *EVENT_ARRAY and *array rather than scalar names in the second anon. array argument to Data::Dumper->new() so that the arrays show up in the output as actual arrays and not array references. Like this

    $ perl -MData::Dumper -e ' @arr1 = qw{ a b c }; @arr2 = qw{ 1 2 3 }; print Data::Dumper->new( [ $,, $", $\, $/, \ @arr1, \ @arr2 ], [ qw{ $, $" $\ $/ *arr1 *arr2 } ] )->Useqq( 1 )->Dump();' $, = undef; $" = " "; $\ = undef; $/ = "\n"; @arr1 = ( "a", "b", "c" ); @arr2 = ( 1, 2, 3 );

    rather than this

    $ perl -MData::Dumper -e ' @arr1 = qw{ a b c }; @arr2 = qw{ 1 2 3 }; print Data::Dumper->new( [ $,, $", $\, $/, \ @arr1, \ @arr2 ], [ qw{ $, $" $\ $/ $arr1 $arr2 } ] )->Useqq( 1 )->Dump();' $, = undef; $" = " "; $\ = undef; $/ = "\n"; $arr1 = [ "a", "b", "c" ]; $arr2 = [ 1, 2, 3 ]; $

    I hope this is of interest.

    Cheers,

    JohnGG