Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
under strict I have to compare a variable which SOMETIMES is undefined. I need to assign the number 1 to it IF it is undefined, but should it already have a value, do nothing.
As expected, you get the use of uninitialized warning error.use warnings; use strict; my $num; if ($num < 0) { $num = 1; } print $num;
I swear once, many years ago, someone showed me something similar to $var || $var = 1; that did just what I needed. I can't seem to remember exactly what it was.
Any help would be appreciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking the value of an undefined value
by kyle (Abbot) on May 10, 2008 at 02:43 UTC | |
|
Re: Checking the value of an undefined value
by pc88mxer (Vicar) on May 10, 2008 at 05:48 UTC | |
|
Re: Checking the value of an undefined value
by Your Mother (Archbishop) on May 10, 2008 at 04:44 UTC | |
|
Re: Checking the value of an undefined value
by Anonymous Monk on May 10, 2008 at 14:55 UTC | |
|
Re: Checking the value of an undefined value
by chrism01 (Friar) on May 12, 2008 at 05:01 UTC |