First off, using the "-w" switch and "use warnings" is redundant. That's just a minor nit.
It would be common to do the enumeration of the %saldi hash outside of the while() loop. The while loop will exit when there is no further data to process. At that point you'll know you've reached EOF, so there's no need to test for it as you are there.
It's also a good practice to test for the validity of the incoming data before you try to do anything significant with it. So, a check of the incoming data along with a check of the @cellen array after the split will keep you from trying to do things with bogus data. Here's just a quick example of what I'm talking about:
#!/usr/bin/perl use strict; use warnings; use diagnostics; my %saldi; while (<>) { chomp; next unless $_; my @cellen = ( split /,/, )[ 3, 4 ]; next unless $cellen[0] && $cellen[1]; $saldi{ $cellen[0] } += $cellen[1]; } $ARGV =~ m/^(\S+)\.txt/; print "$1\n"; foreach my $name ( keys %saldi ) { print "\t$name\t$saldi{$name}\n"; }
In reply to Re: Split pattern doesn't match last line of file
by SheridanCat
in thread Split pattern doesn't match last line of file
by GertMT
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |