in reply to Max Value
%animals_hash = ( $animal => $sums, );
Change that to:
$animals_hash{$animal} = $sums;
Here is a complete working example:
use warnings; use strict; my %animals_hash; while (my $line = <DATA>) { chomp $line; my ( $sums, $animal ) = split /\s+/, $line; $animals_hash{$animal} = $sums; } use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper(\%animals_hash); __DATA__ 455 DOG 1074 BIRD 605 CAT 850 FISH
Outputs:
$VAR1 = { 'BIRD' => '1074', 'CAT' => '605', 'DOG' => '455', 'FISH' => '850' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Max Value
by Scully4Ever (Novice) on Jul 10, 2015 at 17:37 UTC |