Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^7: Time matching YYYY-MM-DD HH:MM:SS.SSS

by dave_the_m (Prior)
on Jul 27, 2012 at 11:34 UTC ( #984017=note: print w/replies, xml ) Need Help??

in reply to Re^6: Time matching YYYY-MM-DD HH:MM:SS.SSS
in thread Time matching YYYY-MM-DD HH:MM:SS.SSS

You probably want something like the following (not heavily tested):
use warnings; use strict; @ARGV == 2 or die; my @files = @ARGV; my $date_qr = qr{^(\d{4}/\d\d/\d\d \d\d:\d\d:\d\d\.\d{3}) }; my @dates; for my $i (0,1) { open my $fh, '<', $files[$i] or die "Can't open $files[$i]: $!\n"; while (<$fh>) { next if /Epoch/; chomp; m/$date_qr/ or die "$files[$i]:$.: invalid line: $_\n"; $dates[$i] = $1; last; } } print "earliest=@dates\n"; my $i = 0; if ($dates[0] ne $dates[1]) { my $earliest = $dates[0] lt $dates[1] ? 0 : 1; open my $fh, '<', $files[$earliest] or die "Can't open $files[$earliest]: $!\n"; while (<$fh>) { next if /Epoch/; chomp; m/$date_qr/ or die "files[$earliest]:$.: invalid line: $_\n"; last if $1 ge $dates[!$earliest]; $i++; } } print "there are $i earlier date entries\n";


Replies are listed 'Best First'.
Re^8: Time matching YYYY-MM-DD HH:MM:SS.SSS
by PRyanRay (Novice) on Jul 27, 2012 at 19:34 UTC
    Wow that's great code except the definition of $date_qr = qr line... The extra space lost me an hour or two this morning. I'm not sure why that made a difference. There is a space after the .\d{3} in the input files. Any ideas? Works like a charm besides that!
      The regex I used works against the sample data you supplied. Perhaps your real data is different. Perhaps you have tabs rather than spaces (so use \s), or perhaps some lines don't have any text after the timestamp?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984017]
[Your Mother]: Americans are still pumping out video games where you get to slaughter as many Germans as you have the GPU for... It has always struck me as odd that this particular case seems fine to people. :\
[LanX]: yep heard the same origin story
[Your Mother]: I like it. I tottered on going into hucksterism because I feel like the world deserves it.
[LanX]: he ... we have a movement here called Anti-Germans based on this
[Corion]: Your Mother: I think that's because (in the west) the Nazi-Germans are recognized as universally evil. Of course, you could do some number games to calculate other measures of evil than "historic losers of second world war" to come up with other evils:)
[Corion]: I've heard "Troll" described as the new Punk, and in a way, it can be as destructive as living the Punk lifestyle, and you don't have to sit out in the cold...
[LanX]: Anti-Germans
[LanX]: Socrates was a Troll
[Your Mother]: It's very, very dangerous... Thinking that a group is intrinsically evil... buries the fact that all humans can be so deep that it starts to become likely they will be.
[Your Mother]: LanX++

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2018-03-19 13:41 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.