I'm trying to solve a problem in Intermediate Perl.
Basically, I open a text file and read its
information. Here is some text from the file:
gilligan.crew.hut lovey.howell.hut 4721
thurston.howell.hut lovey.howell.hut 4046
professor.hut ginger.girl.hut 5768
gilligan.crew.hut laser3.copyroom.hut 9352
gilligan.crew.hut maryann.girl.hut 1180
Basically, the text shows the source of a data
transfer, the destination of that transfer, and the
number of byte's transferred.
Then I modify some code from the book to create a
printout that shows each source machine's total
output.
#!/usr/bin/perl -w
use strict;
my %total_bytes;
while (<>) {
unless (/^#/) {
my ($source, $destination, $bytes) = split;
$total_bytes{$source}{$destination} +=
$bytes;
}
}
my %sum;
for my $source(keys %total_bytes) {
for my $destination ( keys %{ $total_bytes{$source}
}) {
my $sum{$source} += my
$total_bytes{$source}{$destination};
}
}
I think my logic is solid, but I keep getting error
messages:
syntax error at ./sourceOutput.pl line 15, near
"$sum{"
syntax error at ./sourceOutput.pl line 15, near "+="
syntax error at ./sourceOutput.pl line 16, near "}"
Execution of ./sourceOutput.pl aborted due to
compilation errors.
Am I missing something?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>