in reply to foreach - adding newlines?

Ignoring your question for a second,

chomp;

should be

chomp($event_line); # in the loop

or

chomp(@EVENT_ARRAY); # outside the loop

Chomping $_ repeatedly are you are doing is useless since you never use $_.

Back to your question, the only ways to get the output you describe from the code you posted is if:

Would you care to add the following to the end of the code you posted and provide us the output?

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

Update: Fixed bad D::D syntax

Replies are listed 'Best First'.
Re^2: foreach - adding newlines?
by nitehawk (Initiate) on Feb 09, 2009 at 20:47 UTC
    Hrrm - coping the data dumper code results in an error: Usage: PACKAGE->new(ARRAYREF, ARRAYREF) at ./22.pl line 70

      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^2: foreach - adding newlines?
by runrig (Abbot) on Feb 09, 2009 at 20:48 UTC
    You're not ignoring the OP's question...the wrong thing is being chomp'd and that's the source of the problem :-)
      As I mentioned in the OP, I've tried chomp-ing various things in various places - is there somewhere specifically you would recommend? I'm open to try anything.
      Tnx
      Improper chomping doesn't explain the presence of a new line between v1 and v2.
        It does explain it if he's just doing chomp; instead of chomp($some_variable); (expecting perl to magically know what to chomp).