gopikavi has asked for the wisdom of the Perl Monks concerning the following question:
In the above code the output fails to subtract the $input1 and $input2 variables%namesum; open $f,"<data.txt" or die $!; while ($line=<$f>) { chomp $line; next unless $line; $line=~s/[\{\}]//g; @parts=split(/\s+/,$line); ($input1,$input2)=split('/',$parts[2]); $name=substr($parts[0],0,11); $namesum{$name}[0]+=$input1; $namesum{$name}[1]+=$input2; $output=$namesum{$name}[1]-$namesum{$name}[0]; } for $key (sort keys %namesum){ print "\nname:".$key."\n"; print .$namesum{$key}[0]."\n"; print .$namesum{$key}[1]."\n"; print .$output."\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to subtract storage of hashes using perl?
by poj (Abbot) on May 09, 2017 at 06:16 UTC |