0

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

Matteo
  • 14,696
  • 9
  • 68
  • 106
BuzzLightYear
  • 193
  • 1
  • 2
  • 6

3 Answers3

4

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.

Matteo
  • 14,696
  • 9
  • 68
  • 106
  • Thanks, you are right. I was using the wrong way of catching parameters. Could you also help me with the other 2 problems? – BuzzLightYear Oct 25 '12 at 08:06
3

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).

Community
  • 1
  • 1
dan1111
  • 6,576
  • 2
  • 18
  • 29
  • yes, i understand that. just wanted to let know how am trying to find the parameter values. Am able to output html from the result of my perl script. – BuzzLightYear Oct 25 '12 at 08:15
  • dan111 -- Thanks for the way of appending parameters. – BuzzLightYear Oct 25 '12 at 08:33
  • dan111 -- The code window.location.href = url; strangely doesn't execute in firefox. The javascript itself doesnt work – BuzzLightYear Oct 25 '12 at 08:39
  • @BuzzLightYear, sorry that doesn't work for you. I don't have much experience with js myself; I just thought that looked like it might be useful. – dan1111 Oct 25 '12 at 10:48
1

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.