On Mar 17, 2:08 pm, [EMAIL PROTECTED] (Kashif Salman) wrote:
> 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
> ". How can I get rid of that without using "no warnings". I tried 'if
> (defined("$action"))' but that still produces a warning.

perldoc -q quoting

Stop double quoting your variables.  The warning is telling you that
you're using an uninitialized value in a string.  That warning is
important and relevant.  It's telling you that it's the *STRING*
you're checking for defined'ness, not the variable within the string.
The string will *always* be defined, regardless of whether or not the
variable is.

if (defined($action)) { ... }
not
if(defined("$action")) { ... }


$ perl -wle'
my $foo;
if (defined("$foo")) { print "1 yes"; } else { print "1 no" }
if (defined($foo))   { print "2 yes"; } else { print "2 no" }
'
Use of uninitialized value in string at -e line 3.
1 yes
2 no

Paul Lalli


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


Reply via email to