I want to use the Perl CGI module for creating CGI scripts. I went through the documentation available here but I seem to have missed something obvious because I have run into problems with my first program. Here is the HTML:
<form name="form1" method="post" action="http://localhost/cgi-bin/filters.cgi">
<input name="mainbox" type="checkbox"> Mainbox<br> <br>
<input name="n1" type="checkbox">No. 1 <br><br>
<input name="n2" type="checkbox"> No. 2<br><br>
<input name="n3" type="checkbox">No. 3 <br>
<div style="text-align: center;"><input name="Submit" value="Submit" type="submit"></div>
</form>
I simply want the names of the parameters that are passed to the CGI file to be printed on a new page. So (with my limited understanding), I wrote the following in filters.cgi:
#!/xampp/perl/bin/perl -w
use strict;
use warnings;
use CGI;
my $query = CGI->new;
print $query = $query->header('text/html');
my @names = $query->param;
my $q1 = CGI->new;
print $q1->header('text/html');
print $q1->start_html('hello');
foreach my $name (@names) {
print $q1->h1($name);
}
print $q1->end_html;
But this prints out nothing. It does not give me any error either and the syntax is OK. I know I am missing something very simple here but I really want some help with this. How do I write this script correctly? I am using XAMPP in Windows XP, if that makes any difference.
EDIT: Maybe I should mention that I have tried to figure this out myself. So I wrote the following script which works:
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my @arr = ('ac', 'fg', 'ty');
my $q1 = CGI->new;
print $q1->header('text/html');
$q1->start_html('hello world');
foreach my $el (@arr) {
print $q1->p($el);
}
$q1->end_html;
So the problem is somewhere in the parameters being passed. I don't even know where to look for help in the long documentation, so decided to ask here. Also, I have seen the link Nikhil has posted in the comments. One of the points mentioned there is that I should try running my script from the command line. How do I pass these parameters from the command line?