I need some insight on my Perl CGI script.
First of all all this is running under webmin so i'm doing a custom module.
I'm calling a CGI Perl script passing 2 parameter from another Perl CGI. The link I'm calling is in the following format:
http://IP:8080/foobar/alat.cgi?sysinfo=xxxxxxx&SR=yyyyyyyy
The alat.cgi script look like this
#!/usr/bin/perl
use CGI qw(:standard);
ReadParse();
$q = new CGI;
my $dir = $in->param('SR');
my $s = $in->param('sysinfo');
ui_print_header(undef, $text{'edit_title'}.$dir, "");
print $dir."<br>";
print $s"<br>";
The only output I get printed is the value of $dir
and $s
seems to be empty.
What am I doing wrong?
As @Сухой27 said, add
use strict;
, but alsouse warnings;
to the top of your script, right below the shebang (#!/usr/bin/perl
) line. Those will tell you about syntax errors and other stuff where Perl is doing something other than you might intend.With CGI (which is btw not part of the Perl core in the latest 5.22 release any more) and the object oriented approach you are tyring to take, you don't need to use
ReadParse()
. That is an abomination left in from Perl 4'scgilib.pl
times.I don't know what your
ui_print_header
function does. I'm guessing it outputs a bunch of HTML. Are you sure you defined it?With fixing all your syntax errors and using modern syntax, your program would look like this. I'll break down what is happening for you.
Let's look at some of the things I did here.
new CGI
as the CGI docs suggest is fine, but since we are using the OOP way you can use the more commonCGI->new
. It's the same thing really, but it's consistent with the rest of the OOP Perl world and it's more clear that you are calling thenew
method on theCGI
package.$q
, keep using it. There is no$in
.my
.%text
so you can use$text{'edit_title'}
later. Probably you imported that, or ommitted it from the code you showed us.ui_print_header()
. See above.q{}
is the same as''
, but it's clearer that it's an empty string.