http://www.perlmonks.org?node_id=460552


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