The DATA handle can be read using: <DATA> ...the point being that it's not <_DATA_>, it's <DATA>. Then at the end of your script, it is not _DATA_ (with a single underscore on either side), it's __DATA__, with two underscores on each side. At first I thought maybe you just made a typo, but I'm seeing you do it repeatedly, so it's worth mentioning.

As for decoding the JSON first, YES. It doesn't need to be a pattern matching problem (which is almost always much more difficult than people expect) when there are perfectly good JSON parsing modules that will return a structure that you can simply traverse, iterate over, or manipulate however you wish, easily.

Here's how I would start:

use strict; use warnings; use JSON; use Data::Dumper; my $j = JSON->new; my $structure = $j->decode( do { local $/ = undef; <DATA> } ); print Dumper $structure; __DATA__ JSON here.....

Then after getting a look at how my data is structured, I could plan how I want to work with it.

If JSON and JSON::XS seem to heavy for you, try JSON::Tiny, in which case: my $structure = JSON::Tiny->new->decode( ..... );


Dave


In reply to Re^3: Help extracting pattern of data by davido
in thread Help extracting pattern of data by spikeinc

Title:
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, details, 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, summary, 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.