frazap has asked for the wisdom of the Perl Monks concerning the following question:
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: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], ... ];
Now, I would like to automatize the import step. I tried this:use JSON; use Data::Dump "dd"; my $leg_str =<<'END'; { "aa": "label1", "ab": "label2", ... "er": "last label" } END my $leg = decode_json($leg_str);
But this just return in $val the function is have sent... What am I missing ? is there a way to have this working ?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);} +');
Thanks
frazap
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accessing javascript variable from perl
by Corion (Patriarch) on Jun 14, 2019 at 12:26 UTC | |
by LanX (Saint) on Jun 14, 2019 at 12:34 UTC | |
by frazap (Monk) on Jun 14, 2019 at 13:42 UTC | |
by LanX (Saint) on Jun 14, 2019 at 14:51 UTC | |
by frazap (Monk) on Jun 18, 2019 at 07:18 UTC | |
by LanX (Saint) on Jun 18, 2019 at 08:15 UTC | |
by LanX (Saint) on Jun 18, 2019 at 11:15 UTC | |
| |
|
Re: Accessing javascript variable from perl
by LanX (Saint) on Jun 14, 2019 at 12:28 UTC |