Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Seems you want your HH:MM (localtime or GMT?) to match within the given range?

use strict; use warnings; use JSON; use Time::Local; my ($hh, $mm) = (15, 20); # 15:20 while ( my $data = <DATA> ) { my $struct = from_json( $data ); if ( my @res = filter_data_hh_mm( $struct, $hh, $mm ) ) { # ... do something print "Matches: $hh:$mm: [ " .gmtime( $_->[0] ) . ".." . gmtime( +$_->[1] ) . " ]\n" for ( @res ); } } sub filter_data_hh_mm { my ($struct, $hh, $mm) = @_; my @res; for my $line ( @{ $struct->{aaData} } ) { # match if begin is before begin-day HH:MM:59 and # if end is after end-day HH:MM:00 if ( $line->[0] <= epoch_at_hhmmss( $line->[0], $hh, $mm , 59) and epoch_at_hhmmss( $line->[1], $hh, $mm , 0) <= $line->[1] ) { push @res, $line; } } return @res; # matching lines or () } sub epoch_at_hhmmss { my ( $epoch, $hh, $mm, $ss ) = @_; #-- use localtime(), timelocal() if $hh:$mm is in localtime # or adjust $hh:$mm to UTC/GMT accordingly my @epoch0 = gmtime( $epoch ); @epoch0[0..2] = ($ss, $mm, $hh); return timegm( @epoch0 ); } __DATA__ {"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime,re +moteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["13 +75976271","1375976430","LAN","D0:05:FE","",1093,"172.20.28 +.2",1330,"1034,348","0,0"],["1375976246","1375976404","LAN","D0:05:FE +","",1092,"",1327,"1034,348","0,0"],["137597619 +1","1375976381","LAN","D0:05:FE","",1091,"",132 +4,"1034,348","0,0"],["1375976171","1375976314","LAN","D0:05:FE","172. +20.30.2",1090,"",1321,"1034,348","0,0"],["1375976144","137 +5976302","LAN","D0:05:FE","",1089,"",1319,"1034 +,348","0,0"],["1375975155","1375976089","LAN","D0:05:FE"," +",1085,"",1278,"1034,348","0,0"],["1375975194","1375975352 +","LAN","D0:05:FE","",1086,"",1281,"1034,348"," +0,0"],["1375974693","1375974835","LAN","D0:05:FE","",1083, +"",1271,"1034,348","0,0"],["1375974668","1375974827","LAN" +,"D0:05:FE","",1081,"",1268,"1034,348","0,0"],[ +"1375974691","1375974821","LAN","D0:05:FE","",1082,"172.20 +.28.2",1270,"0,0","0,0"],["1375881371","1375881561","LAN","D0:05:FE", +"",1055,"",1122,"1034,348","0,0"],["1375881410" +,"1375881540","LAN","E0:05:AE","",1056,"",1125, +"0,0","0,0"]]}


Matches: 15:20: [ Thu Aug 8 15:19:15 2013..Thu Aug 8 15:34:49 2013 +] Matches: 15:20: [ Thu Aug 8 15:19:54 2013..Thu Aug 8 15:22:32 2013 +]

In reply to Re: Epoch based parser by Perlbotics
in thread Epoch based parser by spikeinc

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Corion]: Meh. Once again I find that SQLite doesn't support window functions and I want to use those nowadays :-)
    [erix]: Look what I found! :P
    [Corion]: Hmm - actually, I don't need them, even though they'd be nice. I just want the (say) 10 latest images, and that's easily done with a limit 10 offset 0 clause, as I don't need all top 10 images for all users.
    [Corion]: erix: Sure, but this is for a really-lightweight application and I'm replacing a CSV file / JSON file for user configuration with SQLite (and optionally, Pg) :)

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (10)
    As of 2018-03-20 13:58 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (253 votes). Check out past polls.