I have a code which takes its input in the form name,amount, i.e. a sample input file might read
Jones,10
Smith,20
Brown,33
All entries for the same name should be added together
My initial code is
What I would like is for entries
Brown,20
and
brown,15
to be added as the same key. Currently I get an entry for Brown and an entry for brown. Any pointers please?
Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
Jones,10
Smith,20
Brown,33
All entries for the same name should be added together
My initial code is
Code:
use strict;
my %results;
open FH, "test.txt" or die "Can't open test.txt\n";
while (<FH>)
{
my ( $name, $amount ) = split /,/;
$results{$name} and $results{$name} += $amount, next;
$results{$name} = $amount;
}
close FH;
foreach my $key ( keys %results )
{ print "$key has $results{$key} pounds\n"; }
Brown,20
and
brown,15
to be added as the same key. Currently I get an entry for Brown and an entry for brown. Any pointers please?
Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.