On Tue, Mar 25, 2003 at 10:42:39AM -0800, Michael Lazzaro wrote:
> But it is certainly possible to extend the initialization capabilities
> to be more robust:
>
> sub foo($x = 'blah') {...} # wrong: use one of the below
> sub foo($x ::= 'blah') {...} # same as C<$x is default('blah')>
> sub foo($x //= 'blah') {...} # sets $x whenever $x is undefined
> sub foo($x ||= 'blah') {...} # sets $x whenever $x is false
While this looks pretty in email, it makes me wonder what the ::
operator does outside of regular expressions and how that operator
interacts with ??::
And don't forget these other argument initializations:
sub foo($x &&= 'blah') {...} # sets $x whenever $x is true
sub foo($x += 1) {...} # add 1 to whatever $x given
sub foo($x -= 1) {...} # subtract 1 to whatever $x given
sub foo($x *= 2) {...} # multiply by 2 whatever $x given
sub foo($x /= 2) {...} # divide by 2 whatever $x given
sub foo($x ~= "foo") {...} # Append "foo" to whatever $x given
Depending on how you're bent, the default() property starts to look
pretty good at this point. :-) (with the others relegated to be the
body of the sub)
-Scott
--
Jonathan Scott Duff
[EMAIL PROTECTED]