http://www.perlmonks.org?node_id=657143


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
    Methinks FunkyMonk hit this on the head....
    and adding Data::Dumper to the mix above,
    use Data::Dumper; print Dumper %hash;
    gives you reasonable (readable) output:
    $VAR1 = 'Pierce'; $VAR2 = { 'Jerrad' => '96' }; $VAR3 = 'Lateur'; $VAR4 = { 'Bart' => '97' }; $VAR5 = 'Miller'; $VAR6 = { 'Katie' => '86' }; $VAR7 = 'Unknown'; $VAR8 = { 'planetscape' => '101' };