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

Hrrm - coping the data dumper code results in an error: Usage: PACKAGE->new(ARRAYREF, ARRAYREF) at ./22.pl line 70

Replies are listed 'Best First'.
Re^3: foreach - adding newlines?
by almut (Canon) on Feb 09, 2009 at 21:32 UTC

    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 )] )); }

      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

Re^3: foreach - adding newlines?
by ikegami (Patriarch) on Feb 09, 2009 at 21:43 UTC