Deb wrote:
> 
> Toby Stuart <[EMAIL PROTECTED]> had this to say,
> > If i understand what u want, the following works (i'll leave the printing to
> > another file up to you)
> 
> Thanks for the quick reply, Toby.  With your suggestions, here's what I
> have (and it works, too).  I have some questions about it, because, as I
> said before, I think I understand hashes, just not what it takes to
> manipulate them.  But I'm too tired right now to form a good question.
> I'll give this some thought and then post some questions.

Reading the perldata document might help.

perldoc perldata


> #!/usr/local/bin/perl
> 
> use strict;
> use warnings;
> 
> my $fileout= "./stats.out";
> my $filein = $ARGV[0];
> my %totals;
> my $date;
> my $count;
> 
> open (F, "$filein") || die "Oops, did you type the right filename?\n";

You should include the $! variable in the error message to find out why
the error occured.

open F, $filein or die "Oops, did you type the right filename? $!";


> while (<F>)
> {
>    chomp($_);
>    ($date,$count) = split(/,/,$_);
>    $totals{$date} += $count;
> }
> close(F);
> 
> while ( ($date,$count) = each %totals)
> {
>    open (F,">>$fileout") || die "Cannot open $fileout for writing.\n";
>    print F "$date : $count\n";
> }
> close(F);

There is no reason to open and close the file a lot of times, just open
it once.

open F, ">> $fileout" or die "Cannot open $fileout for writing. $!";

while ( ( $date, $count ) = each %totals )
{
   print F "$date : $count\n";
}
close F;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to