in reply to Best method of assigning "default" values?
It would also be useful to have // (or equivilent) as a normal short circuit operator as well, although this is really syntactic sugar for defined and existing operators.my $foo ||= 1; # $foo is set to '1' if it was previously a false value my $bar //= 1; # $bar is set to '1' only if it was undefined (0 and em +pty string don't count).
Not quite as pretty, but better than a full if block.sub routine { my $input_ref = {@_}; my $var1 = defined $input_ref->{var1} ? $input_ref->{var1} : + 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Best method of assigning "default" values?
by mrborisguy (Hermit) on Jun 29, 2005 at 03:10 UTC |