in reply to Deciphering the output from Data::Dumper
You've confused their first and last names. The data is <lname fname score> but you assign those to $fname, $lname, $score
my %hash = (); while( <DATA> ) { my( $lname, $fname, $score ) = split; $hash{$lname}{$fname} = $score; } #just last names print join "\n", keys %hash; print "\n---\n"; #names and scores: for my $lname ( keys %hash ) { for my $fname ( keys %{ $hash{$lname} } ) { printf "$lname, $fname: $hash{$lname}{$fname}\n" } } __DATA__ Lateur Bart 97 Pierce Jerrad 96 Unknown planetscape 101 Miller Katie 86
Output:
Pierce Lateur Miller Unknown --- Pierce, Jerrad: 96 Lateur, Bart: 97 Miller, Katie: 86 Unknown, planetscape: 101
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Deciphering the output from Data::Dumper
by ww (Archbishop) on Dec 15, 2007 at 12:36 UTC |
In Section
Seekers of Perl Wisdom