Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Split pattern doesn't match last line of file

by GertMT (Hermit)
on Jan 02, 2007 at 06:58 UTC ( [id://592497]=note: print w/replies, xml ) Need Help??


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

couldn't get this to work. I'll investigate further
  • Comment on Re^2: Split pattern doesn't match last line of file

Replies are listed 'Best First'.
Re^3: Split pattern doesn't match last line of file
by graff (Chancellor) on Jan 03, 2007 at 01:33 UTC
    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"; } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://592497]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found