Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Deciphering the output from Data::Dumper

by FunkyMonk (Chancellor)
on Dec 14, 2007 at 23:32 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://657143]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-24 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found