http://www.perlmonks.org?node_id=1049395


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

Hi Ken,

Thanks for a quick response.

Note: you haven't supplied data that matches your original 12:15 or subsequent any:20 — I've made an additional change in order to get some output.

indeed I have two scripts, one that does time based as you had given me, and the other one that takes in file as an input and then parses json. This script (in the above post) takes input (as json output from a webpage logged to the file) and parses it.

I want to attach the file but I am not sure how I can do that. I tried it as above but it gives me the foll. error:

use strict; use warnings; use Time::Local; use JSON; use File::Read; 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 } } }
What does having while(<DATA>) do? Does it read till end of the _DATA_ ? if so is it correct that in my above case I do a while($jsonc)? I understood the substitution part, thanks a lot. However, in my case when I parse my file I get the below error:
c:\perl>perl json.pl Use of uninitialized value $_ in substitution (s///) at get.pl line 14 +. malformed JSON string, neither array, object, number, string or atom, +at character offset 0 (before "(end of string )") at get.pl line 15.
Content of json.txt looks pretty much same as what you have mentioned above in the _DATA_ section.And I can clearly see that the end of first json block has a "]]}\n". So its supposed to work as you mentioned.