http://www.perlmonks.org?node_id=180983


in reply to Re: Re: On Responsible Considerations
in thread On Responsible Considerations

Here is an example. There are MANY posts on PM about CGI scripts. Most of the books I have read on writing them, including Perl books, seem to agree that any page that wants to be even remotely high performance needs to have some javascript to avoid needless round trips to the server for poor form input and the like. PM has been a very poor place to learn how to write perl scripts that do this, partly because javascript discussion is looked down upon here. JS sites, on the other hand, don't show perl scripts like this because they want to avoid the Perl focus. I had an application a few months ago where I wanted to use JS in a Perl script to re-sort a short list in a cgi form without requiring a round trip to the server. I needed to have the Perl script write the code to fill the JS array. Being somewhat new to both Perl and JS, I had much difficulty finding examples of how to do this, and felt there should have been much more in Supersearch about writing JS with Perl.

Everything you do in JavaScript, has nothing to do with Perl.
Everything you do in Perl, has nothing to do with JavaScript.

You may be using one language to generate code for the other, or maybe you found a way to use both languages together, but with normal CGI programming, you have strict separation of client and server side.

You needed some Perl to fill a JS array. Surprise: that has nothing to do with JS, only with its syntax. You would probably want to generate JS, which is (from Perl's view) just a string of code:

my @foo = qw(foo bar baz); my $js = 'foo = new Array(' . join(', ', map "'\Q$_\E'", @foo) . ');';
Or something like that.

HTML and Javascript have nothing to do with Perl, but generating them can have. But when generating a string, it doesn't matter if it's executable code or just a string of repeated characters.

Generating Javascript code ("a string") with Perl is of course not off topic, Javascript itself would be. (Such as the recent question about closing a pop-up window. I'm not linking to it, because I hope it's reaped by now :)

By the way, have a look at Data::JavaScript.

any page that wants to be even remotely high performance needs to have some javascript to avoid needless round trips to the server for poor form input and the like.

That is HTTP, HTML, CGI and server maintenance related. It is NOT Perl related! CGI can be written in any programming language that can handle environment variables and stdin/stdout. Yes, you can write CGI programs in C, GW-Basic, Pascal, Visual Basic or even Brainfuck if you don't care about the environment variables.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.