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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|