Question about using the Perl CGI module:
Let's say I have a sub called foo that accepts two parameters defined as follows:
sub foo {
local($a, $b) = @_;
print "a= [$a]";
}
In my main routine, I take some form parameters and pass them to foo like this:
use CGI;
$cgi = CGI->new;
foo($cgi->param('field1'), $cgi->param('field2'));
If the form did not pass in a value for field1, (in my case, a SELECT field called field1 with no values to choose from was used), the sub foo sets $a to the value that was passed in $cgi->param('field2'), which was a non-empty value.
Can someone help me understand why this happens and why $a isn't simply a blank ('') value and $b = the value sent in from $cgi->param('field2')?
I'm sure there's a logical reason, but I'm not a Perl pro so I'm sure it's something I've yet to learn or understand about Perl.
Thanks in advance!
localhere (and you should not use$aand$bas variable names as those are specially used forsort.) You want to usemy ( $foo, $bar ) = @_;- friedolocalis really badly named. It doesn't create local variables. You create localised variables that work as you'd expect them to, always usemy. - Dave Cross