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

Re^5: Epoch based parser

by kcott (Chancellor)
on Aug 14, 2013 at 09:26 UTC ( #1049403=note: print w/replies, xml ) Need Help??

in reply to Re^4: Epoch based parser
in thread Epoch based parser

When I first read your latest post, the code looked like this:

my $jsonc = read_file ('H:\Work\perl\latest\Scripts\logs\json.txt'); local $/ = "}"; while ($jsonc) { s/\n[+]?//gm; my $data = decode_json $jsonc; for (@{$data->{aaData}}) { #my print function }

I wrote some more example code, dug up a few more references to help you out and started to respond. Upon doing so, I find you've changed that code to this:

my $jsonc = read_file ('H:\Work\perl\latest\Scripts\logs\json.txt'); { local $/ = "}\n"; while ($jsonc) { s/\n[+]?//gm; my $data = decode_json $_; for (@{$data->{aaData}}) { #my print/parse function } } }

If you make changes then clearly indicate what you've changed! See "How do I change/delete my post?".

Here's the new example code I wrote:

#!/usr/bin/env perl -l use strict; use warnings; use JSON; use Time::Piece; my $json_file = 'json.txt'; my $wanted_minute = 40; open my $json_fh, '<', $json_file or die "Can't read '$json_file': $!" +; { local $/ = "}\n"; while (<$json_fh>) { s/\n[+]?//gm; my $data = decode_json $_; for (@{$data->{aaData}}) { print "@$_" if is_wanted_time(@$_[0,1]); } } } close $json_fh; sub is_wanted_time { for (@_) { my $t = gmtime $_; return 1 if $t->min == $wanted_minute; } return 0; }

With this input:

$ cat json.txt {"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime, remoteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["1 +375976271" ,"1375976430","LAN","D0:05:FE","",1093,"",1330," +1034,348"]]} {"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime, remoteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["1 +375976271" ,"1375976430","LAN","D0:05:FE","",1093,"",1330," +1034,348"]]}

Here's the output (it's the same as from the last example, i.e.

$ 1375976271 1375976430 LAN D0:05:FE 1093 1330 1 +034,348 1375976271 1375976430 LAN D0:05:FE 1093 1330 1 +034,348

Here's some more references:

-- Ken

Replies are listed 'Best First'.
Re^6: Epoch based parser
by spikeinc (Acolyte) on Aug 15, 2013 at 05:41 UTC

    G'Day Ken. I am extremely sorry for doing the edits without notifying. I was trying out couple of things and wanted to post the latest.

    However, your logic really helped and I thank you for that. I learnt a few things and also implemented some more regexp related filtering and it works great!!!

    I appreciate your help and thankful to you in helping me learn perl so far :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1049403]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-06-24 06:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.