in reply to Re: Comparing masses in two txt files
in thread Comparing masses in two txt files

I'm a bit puzzled by the use of length in this line.

my @data1 = grep {chomp; length} <$in1>;

I would have though you want the chomped data so just pass out $_ instead.

my @data1 = grep {chomp; $_} <$in1>;

Maybe I'm missing something obvious.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^3: Comparing masses in two txt files
by GrandFather (Saint) on Nov 05, 2008 at 21:33 UTC

    The grep is there to skip blank lines hence the length. Putting the chomp in the grep in that fashion avoids a map:

    my @data1 = grep length, map chomp, <$in1>;

    You don't "pass out" the value from grep. It tests the result returned for each element of the source list to determine if the element is placed in the output list.


    Perl reduces RSI - it saves typing
      Doh! I must have taken some "stupid" pills with breakfast today :-(

      However, that map chomp, <$in1>; will result in a load of '1's being emitted to the grep denoting the success of the chomps. The whole line should perhaps be

      my @data1 = grep length, map {chomp; $_} <$in1>;

      Obviously, your original line was fine and I'm sorry my buffle-headed senior moment got us into this :-/

      Cheers,

      JohnGG