Here's my little Javascript Perl Interpreter. It's much easier than you think.
#!/usr/bin/perl ###################################################################### +######### # JtoP.cgi + # # + # # This program is distributed in the hope that it will be useful, + # # but WITHOUT ANY WARRANTY; without even the implied warranty of + # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # # GNU General Public License for more details. + # # + # # + # # Last modified: 06/27/10 + # ###################################################################### +######### # Set-up the cgi enviroment # this little gizmo is something I adopted # and works like a champ use CGI; $query = new CGI; @names = $query->param; foreach $parameter (@names) { $_ = $query->param($parameter); $input{$parameter} = $_; } # we won't have this until the Ajax kicks in after page load # then it happens quietly behind the scenes if ($_) { $screenwidth = $input{'screenwidth'}; $screenheight = $input{'screenheight'}; $availwidth = $input{'availwidth'}; $availheight = $input{'availheight'}; $screen = "$input{'screenwidth'} x $input{'screenheight'}"; $availscreen = "$input{'availwidth'} x $input{'availheight'}"; $colordepth = $input{'colordepth'}; open(FILE, ">>foobat.txt"); print FILE "$screen\n"; print FILE "$availscreen\n"; print FILE "$colordepth\n"; close FILE; } # no HTML here just get to the Ajax and send the data print "content-type: text/html\n\n"; print qq~ <script type="text/javascript"> // OOAjax thanks to Patrick Hunlock function ajaxObject(url, callbackFunction) { var that=this; this.updating = false; this.abort = function() { if (that.updating) { that.updating=false; that.AJAX.abort(); that.AJAX=null; } } this.update = function(passData,postMethod) { if (that.updating) { return false; } that.AJAX = null; if (window.XMLHttpRequest) { that.AJAX=new XMLHttpRequest(); } else { that.AJAX=new ActiveXObject("Microsoft.XMLHTTP"); } if (that.AJAX==null) { return false; } else { that.AJAX.onreadystatechange = function() { if (that.AJAX.readyState==4) { that.updating=false; that.callback(that.AJAX.responseText,that.AJAX.status,that.A +JAX.responseXML); that.AJAX=null; } } that.updating = new Date(); if (/post/i.test(postMethod)) { var uri=urlCall+'?'+that.updating.getTime(); that.AJAX.open("POST", uri, true); that.AJAX.setRequestHeader("Content-type", "application/x-www- +form-urlencoded"); that.AJAX.setRequestHeader("Content-Length", passData.length); that.AJAX.send(passData); } else { var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getT +ime()); that.AJAX.open("GET", uri, true); that.AJAX.send(null); } return true; } + } var urlCall = url; this.callback = callbackFunction || function () { }; } // get the variables //var sw = document.getElementById("screenwidth").value; //var sh = document.getElementById("screenheight").value; //var aw = document.getElementById("availwidth").value; //var ah = document.getElementById("availheight").value; //var cd = document.getElementById("colordepth").value; var sw = screen.width; var sh = screen.height; var aw = screen.availWidth; var ah = screen.availHeight; var cd = screen.colorDepth; // the Ajax object var myRequest = new ajaxObject('JtoP.cgi'); // the query string var sendString = 'screenwidth='+sw+'&screenheight='+sh+'&availwidt +h='+aw+'&availheight='+ah+'&colordepth='+cd; // and go man go myRequest.update(sendString,'POST'); </script> ~; 1;
It works without form fields. It send the javascript data straight to Perl upon page load. Maybe too simple but it works like a charm. Ted Cambron tedcambron@hotmail.com

In reply to Re: javascript interpreter in perl??? by Anonymous Monk
in thread javascript interpreter in perl??? by monkster

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.