Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: storing data in a hash

by GrandFather (Saint)
on Jun 21, 2006 at 21:54 UTC ( [id://556783]=note: print w/replies, xml ) Need Help??


in reply to storing data in a hash

I suspect what you are looking for is a hash of arrays. The following code may get you headed in the right direction:

use strict; use warnings; my %dailyRecords; while (<DATA>) { chomp; next if ! length; my @record = split; # Pull out the data fields # Pull out Date and generate a date stamp my @now = reverse ((localtime ($record[1]))[3..5]); my $dateStamp = join '', map {sprintf '%04d', $_} @now; # Append this record to list keyed by date stamp push @{$dailyRecords{$dateStamp}}, [@record]; } for (sort keys %dailyRecords) { print "Day stamp: $_\n"; my @daysRecords = @{$dailyRecords{$_}}; print "@$_\n" for @daysRecords; } __DATA__ 1149621887 1149623161 NG004193@net.NET 3 820 156 1 +7570249 1149621900 1149623197 NG004193@net.NET 1 648 80 0 +0 1149692376 1149694912 NG004193@net.NET 3 7932259 243 8 +5227944 1149695677 1149695693 Sinkbad@net.net 1 49385 0 0 +0

Prints:

Day stamp: 010600050007 1149621887 1149623161 NG004193@net.NET 3 820 156 17570249 1149621900 1149623197 NG004193@net.NET 1 648 80 00 Day stamp: 010600050008 1149692376 1149694912 NG004193@net.NET 3 7932259 243 85227944 1149695677 1149695693 Sinkbad@net.net 1 49385 0 00

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (9)
As of 2024-04-23 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found