in reply to Re^2: sorting logfiles by timestamp
in thread sorting logfiles by timestamp
From the information provided, I can see no need for that complex data structure (i.e. @{$myHash{$data2}{info}}).
This code produces the output you say you want:
#!/usr/bin/env perl -l use strict; use warnings; use Time::Piece; my @data; while (<DATA>) { my ($date, $time, $data1, $data2) = split; my $key = Time::Piece->strptime("$date $time", '%m/%d/%Y %H:%M:%S' +)->epoch; push @data, [$key, "$date,$time,$data1,$data2"]; } print for map { $_->[1] } sort { $a->[0] <=> $b->[0] } @data; __DATA__ 01/14/2014 23:44:14 A Y 01/14/2014 23:44:12 B Y 01/14/2014 23:44:13 C X 01/14/2014 23:44:12 D X
Output:
01/14/2014,23:44:12,B,Y 01/14/2014,23:44:12,D,X 01/14/2014,23:44:13,C,X 01/14/2014,23:44:14,A,Y
If that doesn't do exactly what you want, it should at least provide sufficient information for you to attempt a solution yourself. If you do need further help, please ensure you post the missing details.
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: sorting logfiles by timestamp
by Jim (Curate) on Jan 21, 2014 at 22:57 UTC | |
by kcott (Archbishop) on Jan 22, 2014 at 14:37 UTC | |
by Jim (Curate) on Jan 22, 2014 at 18:04 UTC | |
by kcott (Archbishop) on Jan 23, 2014 at 13:59 UTC | |
by Jim (Curate) on Jan 24, 2014 at 16:50 UTC | |
|
Re^4: sorting logfiles by timestamp
by Anonymous Monk on Jan 22, 2014 at 14:05 UTC |