I have a javascript file that contains a bunch of variables.
var leg = { aa: "a label", ab: "another label", .... }; var map = { aa : ["R1"], ab : ["AA1"], ac : ["AA1", "AA2"], .... }; var monorows = [ ["R6", "c", "1", "CB16", "CB15" ... codes that are listed in map], ... ];
I want to check that these variables are coherent, eg all codes in map are also in monorows, etc. In a first step, I copied the javascript variables in a perl script, changed the syntax to have json data instead of javascript syntax and could run my checks:
use JSON; use Data::Dump "dd"; my $leg_str =<<'END'; { "aa": "label1", "ab": "label2", ... "er": "last label" } END my $leg = decode_json($leg_str);
Now, I would like to automatize the import step. I tried this:
use WWW::Mechanize::PhantomJS; my $js = WWW::Mechanize::PhantomJS->new(); $js->get_local("my_js_file.js"); #print $js->content; I get the content ok here. my ($val, $type) = $js->eval_in_page('function(){JSON.stringify(leg);} +');
But this just return in $val the function is have sent... What am I missing ? is there a way to have this working ?

Thanks

frazap


In reply to Accessing javascript variable from perl by frazap

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.