Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Deciphering the output from Data::Dumper

by FunkyMonk (Chancellor)
on Dec 14, 2007 at 23:32 UTC ( #657143=note: print w/replies, xml ) Need Help??


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' };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://657143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2021-05-17 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (157 votes). Check out past polls.

    Notices?