macchisp
08-02-2006, 09:25 PM
I am passing parameters through my perl scripts and sometimes the parameters can be undefined. If they are undefined, I want to set them to a specific value.
Here is a snippet of my code:
my $num = param('num');
if(undef($num)) {$num = 5;}
print "$num";
I am purposly giving it an undefined value because I want to check it using print. When I do this, I get a warning that says "use of uninitialized value in concatenation (.) or string in line 21..." Every other part of the script works, except this print method, nothing gets printed and I think it's because it is still undefined. It runs fine but I don't want to make the error log longer than it has to be. I'm trying to make my code efficient.
How can I get it to define the value to 5? Are there any other ways that are better?
Thanks for your help.
Here is a snippet of my code:
my $num = param('num');
if(undef($num)) {$num = 5;}
print "$num";
I am purposly giving it an undefined value because I want to check it using print. When I do this, I get a warning that says "use of uninitialized value in concatenation (.) or string in line 21..." Every other part of the script works, except this print method, nothing gets printed and I think it's because it is still undefined. It runs fine but I don't want to make the error log longer than it has to be. I'm trying to make my code efficient.
How can I get it to define the value to 5? Are there any other ways that are better?
Thanks for your help.