Created
July 1, 2014 02:46
-
-
Save weidagang/82730ca3f6a1d4a187be to your computer and use it in GitHub Desktop.
Perl: timespan between 2 keywords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use File::Basename | |
$nargs = @ARGV; | |
sub usage() { | |
my $prog = basename($0); | |
print "Usage: $prog <start-text> <end-text>\n"; | |
} | |
if ($nargs != 2) { | |
usage(); | |
exit 1; | |
} | |
$start = quotemeta($ARGV[0]); | |
$end = quotemeta($ARGV[1]); | |
while(<STDIN>) { | |
if (/(\d+):(\d+):(\d+).(\d+).*$start/) { | |
$h1 = $1; | |
$m1 = $2; | |
$s1 = $3; | |
$ms1 = $4; | |
$t1 = $1 * 60 * 60 * 1000 + $2 * 60 * 1000 + $3 * 1000 + $4; | |
} | |
if (/(\d+):(\d+):(\d+).(\d+).*$end/) { | |
$h2 = $1; | |
$m2 = $2; | |
$s2 = $3; | |
$ms2 = $4; | |
$t2 = $1 * 60 * 60 * 1000 + $2 * 60 * 1000 + $3 * 1000 + $4; | |
if ($t1 > 0) { | |
$diff = $t2 - $t1; | |
print "t1=$h1:$m1:$s1.$ms1, t2=$h2:$m2:$s2.$ms2, interval=${diff}ms\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment