one of the options: create a webpage that check the availability of the file
with some interval
<html> <body onload = 'init()'> <script lang = 'text/javascript'> function init(){ setInterval(function(){ get('numbers.json', function(r){ if(r == 'error'){ console.log('waiting for data'); } for(var i in r['num']){ console.log(r['num'][i]['text'] + ': ' + r['num'][i]['value']); } })}, 5000); } function get(file, callback){ var xmlHttpRequest = new XMLHttpRequest(); xmlHttpRequest.open('GET', '/' + file, true); xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-for +m-urlencoded'); xmlHttpRequest.onreadystatechange = function (){ if(xmlHttpRequest.status == 404){ xmlHttpRequest.abort(); callback('error'); return; } if(xmlHttpRequest.status == 200 && xmlHttpRequest.readyState == 4) { callback(JSON.parse(xmlHttpRequest.responseText)); return; } } xmlHttpRequest.send(); } </script> </body> </html>
then perl script which prepares json:
%a = qw/one 1 two 2 three 3 four 4 five 5/; $l = keys %a; open OUT,'>numbers.json' or die $!; print OUT "{\"num\":[\n"; for(sort keys %a){ print OUT '{"text":"'.$_.'", "value":"'.$a{$_}.'"}'; --$l ? print OUT ",\n" : print OUT "\n"; } print OUT "]}\n"; close OUT;
everything goes around and checks the file
if there is none, the thing is ok with it
once the file appears, it loads its innards
ugly ? yes,
working ? also yes
alrighty then

In reply to Re: Providing perl array data to javascript code by Lennotoecom
in thread Providing perl array data to javascript code by nikmit

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.