in reply to Split pattern doesn't match last line of file

How about this:
... while (<>) { next unless (/,/); ...
In other words, simply skip lines that don't contain a comma. Everything else could stay the same.

Replies are listed 'Best First'.
Re^2: Split pattern doesn't match last line of file
by GertMT (Hermit) on Jan 02, 2007 at 06:58 UTC
    couldn't get this to work. I'll investigate further
      It shouldn't be that much trouble. If the OP script works most of the time (except when there's a file with a blank line), then just adding the "next" statement as shown (first line of code inside the while loop) should work all the time:
      #!/usr/bin/perl -w use strict; use warnings; use diagnostics; my %saldi; while (<>) { next unless ( /,/ ); ## add this line my @cellen = ( split /,/, )[ 3, 4 ]; $saldi{ $cellen[0] } += $cellen[1]; if ( eof(ARGV) ) { $ARGV =~ m/^(\S+)\.txt/; print "$1\n"; foreach my $name ( keys %saldi ) { print "\t$name\t$saldi{$name}\n"; } } }