Chris Devers wrote:
On Sun, 2 Jan 2005, Siegfried Heintze wrote:
I am posting this query in beginners instead of beginners-cgi because I
believe this is a question about the defined statement and not the $q->param
statement/function.
I'm using this code:
$q = new CGI;
my $nUserId = $q->param("userId") ;
I was hoping the defined keyword would tell me if userId was present, but it
does not seem to be doing that.
How can I make this execute the die statement when userId is missing from my
get/post parameters?
if (defined $nUserId) {
$juror_number = $nUserId;
} else {
die "No valid ID for User";
}
I usually just write in a way similar to this:
my $q = new CGI;
my $nUserId = $q->param("userId") or die "No valid ID for User";
Or if I'm feeling less draconian,
my $nUserId = $q->param("userId") or "No valid ID for User";
That will provide you with the warning:
Useless use of a constant in void context at PROGRAM line N.
provided that you have warnings enabled. You probably meant to write:
my $nUserId = $q->param("userId") || "No valid ID for User";
which does what you intended.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>