Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Creating a hash of arrays from DB results

by ramlight (Friar)
on Oct 05, 2009 at 20:43 UTC ( [id://799344]=note: print w/replies, xml ) Need Help??


in reply to Creating a hash of arrays from DB results

This problem splits nicely into two parts: getting the data from the database and building the hash of arrays. I'm going to assume that you have (or will) solve the database portion. So here is how to build the hash of arrays:
my %state_hash; while (<DATA>) { chomp; my ($stamp,$state) = split/\s*\|\s*/; print "$stamp $state\n"; push @{$state_hash{$stamp}}, $state; } print "\n"; for my $stamp (sort keys %state_hash ) { print "$stamp: @{ $state_hash{$stamp} }\n"; } __DATA__ 200910021546 | Dormant 200910021546 | In Use 200910021352 | In Use 200910021352 | Dormant 200910021352 | In Use 200910021125 | In Use 200910021125 | In Use 200910021125 | Dormant
Which prints:
perl stampstate.pl 200910021546 Dormant 200910021546 In Use 200910021352 In Use 200910021352 Dormant 200910021352 In Use 200910021125 In Use 200910021125 In Use 200910021125 Dormant 200910021125: In Use In Use Dormant 200910021352: In Use Dormant In Use 200910021546: Dormant In Use

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found