Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Making a hash of arrays from a datafile

by TedPride (Priest)
on Oct 19, 2004 at 23:14 UTC ( [id://400696]=note: print w/replies, xml ) Need Help??


in reply to Making a hash of arrays from a datafile

use strict; use warnings; my %hash; m/(\d+),(\d+)/ and push(@{$hash{$1}}, $2) for <DATA>; for (sort keys %hash) { print "$_ => "; print "$_ " for sort @{$hash{$_}}; print "\n"; } __DATA__ 2,6 2,3 1,2 2,5 1,3 1,4
This creates a hash with the first value as key and all the second values pushed into nested arrays. Sorting and printing is simple, as seen above.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found