Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: null values

by monarch (Priest)
on May 26, 2005 at 08:08 UTC ( #460552=note: print w/replies, xml ) Need Help??


in reply to null values

This has to be one of the most common initial questions that comes up about perl.

if ( defined( $q->param( "myinput" ) ) ) { print( $q->param( "myinput" ) ); }

or

my $value = $q->param( "myinput" ); print( $value ) if ( $value );

The above only works if $value is never going to be zero, because zero evaluates to false. A value of undef or zero is false. The following is safer:

my $value = $q->param( "myinput" ); print( $value ) if ( defined( $value ) );

Replies are listed 'Best First'.
Re^2: null values
by fluffyvoidwarrior (Monk) on May 26, 2005 at 08:15 UTC
    Thanks People

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://460552]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2022-11-28 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?