3

Ok I'll try and be as detailed as possible.

I need to connect to a https url that streams JSON data, and search for keywords via REGEX as the data streams then take the matching JSON element decode it and insert it into a database.

The REGEX on is not the problem that's relatively simple.

What I'm struggling with is reading the data line wise. I've tried a few examples I found online the use LWP but where the stream never stops loading the script hangs.

Here's the closest I've gotten

#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;
use IO::String;

my $handle = IO::String->new(get("https://stackoverflow.com"));
while (defined (my $line = <$handle>)) {
  print $line; #Inserted for testing

  #Decode and insert into DB here       
}
close $handle;

The data comes in a fairly fast rate so the script has to be efficient.

Any pointers as to how to get this done would be great.

Thanks Sean

Sean Smith
  • 85
  • 5

1 Answers1

1

JSON::SL can help you.

Also see Chas. Owens' answer where he compares JSON::SL and JSON::Streaming::Reader.

Community
  • 1
  • 1
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133
  • That helps a lot with processing the JSON still can't get my head around feeding the incoming data to JSON::SL. – Sean Smith Apr 07 '17 at 15:21