Kashif Salman wrote:
Hello,

Hello,

I have a CGI script; when it runs the very first time I define some variables
my $action = $q->param('action');

The first time it runs, parameter 'action' isn't defined so that is
how I check that it is running the first time and do my things

if ($aciton eq "") {...}
elsif ($action eq "submit") {...}

the elsif runs if I hit a button on a form which has a hidden field
that sets action="submit". My question is that the script produces a
warning on the if statement " Use of uninitialized value in string eq
".

$ perl -le'
use warnings;
use strict;

my $action;

if ( $action eq "" ) {
    print "\$action is empty";
    }
'
Use of uninitialized value in string eq at -e line 7.
$action is empty


How can I get rid of that without using "no warnings". I tried 'if
(defined("$action"))' but that still produces a warning.

$ perl -le'
use warnings;
use strict;

my $action;

if ( defined "$action" ) {
    print "\$action is empty";
    }
'
Use of uninitialized value in string at -e line 7.
$action is empty


You are not testing the variable $action. You are testing a string that just happens to contain the variable $action. defined() needs to test the actual variable itself:

if ( defined $action ) {


Also see the FAQ entry:

perldoc -q quoting



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to