in reply to Re: CGI: Passing variables to a subroutine
in thread CGI: Passing variables to a subroutine
This generates a warning (uninitialized value in string eq) when button does not already exist in the $query object.
Declaring variables helps keep track of what input is expected and set default values when none exists:my $query = CGI->new(); if ($query->param( "button" ) eq 'first') { display_first( $query ) }
This generates a different warning (uninitialized value in hash element):my $region = $query->param( "region" ) || 42; my $button = $query->param( "button" ) || ''; if ($button eq 'first') { # '' gives no warning
my $handler = $handlers{$query->param( "button" )};
|
|---|