in reply to Best method of assigning "default" values?

I've heard a future version of Perl (5.10.x ?) is going to have a new operator that assigns if undefined, ie.
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).
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.

In the meain time, personally, I would use:
sub routine { my $input_ref = {@_}; my $var1 = defined $input_ref->{var1} ? $input_ref->{var1} : + 1; }
Not quite as pretty, but better than a full if block.

Replies are listed 'Best First'.
Re^2: Best method of assigning "default" values?
by mrborisguy (Hermit) on Jun 29, 2005 at 03:10 UTC

    Also, I believe Perl6 already has the //= operator, as well.

        -Bryan