in reply to javascript interpreter in perl???

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

Replies are listed 'Best First'.
Re^2: javascript interpreter in perl???
by Anonymous Monk on Jun 28, 2010 at 00:35 UTC
      Call it what you will. It works and a whole lot better than any solution you have given.

        You could call a bucket and mop a box of chocolates. The bucket and mop may "work" for some unrelated activity but that doesn't make them delicious or edible. The previous answers relating to Mechanize, JE, DOM, etc were on point.