in reply to Re^2: Conditional initialization of my-variables
in thread Conditional initialization of my-variables
> $input = 1 unless $input;
Careful! Many things are false in Perl, like 0 or ""
You probably meant
$input = 1 unless defined $input;
Anyway, both are IMHO better written as
$input ||= 1; # default if false # or $input //= 1; # default if undefined
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Conditional initialization of my-variables
by Bod (Parson) on Apr 08, 2023 at 17:55 UTC | |
by LanX (Saint) on Apr 08, 2023 at 18:24 UTC | |
by kcott (Archbishop) on Apr 08, 2023 at 19:49 UTC |