BuzzLightYear
BuzzLightYear

Reputation: 193

passing variables to perl script from html

I am trying to call a perl script from my HTML page. The way am trying to do is to call the url of the perl script located on the server.

Here is the piece of code:

HTML:

var fname = "Bob";
var url='http://xxx.com:30000/cgi-bin/abc.pl?title=fname';  
window.open(url,"_self");                       

The way am trying to retrieve it in perl as:

Perl:

print "$ARGV[0]\n";

Now, I have 3 questions:

  1. I think this is the correct way to pass the variables but am not able to print the argument in perl.
  2. If i want to pass another variable lname, how do i append it to the url?
  3. My window.open should open the output in the same window, since it uses the parameter _self. Still it doesn't.

Could anybody point out the problems?

Thanks, Buzz

Upvotes: 0

Views: 7617

Answers (3)

Mark Leavenworth
Mark Leavenworth

Reputation: 61

There are two different environments that each pass variables two different ways. The command line can pass variables through the @ARGV and the browser can pass variables through @ENV. It doesn't matter what language you use, those are the arrays that you will have to employ.

Upvotes: 1

dan1111
dan1111

Reputation: 6566

In addition to what Matteo said, a simple print statement is not enough to send some output to the browser.

Please see a recent answer I wrote giving a sample CGI script with output.

In regard to your other issues:

Variables are appended to a url separated with &:

var url='http://xxx.com:30000/cgi-bin/abc.pl?title=fname&description=blah';

Based on this question, perhaps you should try window.location.href = url; instead (though that doesn't explain why your code isn't working).

Upvotes: 3

Matteo
Matteo

Reputation: 14930

No @ARGV contains command line arguments and will be empty.

You need the CGI module

use warnings;
use strict;

use CGI;
my $query = CGI->new;
print $query->param( 'title' );

Edit: Take a look at dan1111's answer on how to generate HTML and display it in the browser.

Upvotes: 4

Related Questions