Or as more flexible approach "you can use "@_" and "$_" in prototypes to flag parameters which default to $_ if missing"Is this a claim (that you can already do this) or a suggestion? If it's a claim, then note that _ is already a valid character in prototypes for a scalar argument defaulting to $_, as you want. If it's a suggestion, then I think that having a prototype syntax like @_ would be very confusing (besides being ambiguous, given that it conflicts with a currently valid, although useless, prototype), since @_ already has a quite different meaning.
By the way, notice that Params::Validate has a very rich defaults syntax for this sort of thing. In particular, you can do something like
validate_pos 1, ( { default => $_ } ) x ( @_ - 1 )
UPDATE: Oops, that last snippet doesn't make any sense. Indeed, as I think about it further, what does it mean to have an array of values, all of which default to $_ if absent? I think it's best to stick with the case of allowing explicitly listed parameters to default:
validate_pos 1, ( { default => $_ } ) x 57
In reply to Re^3: why does push not default to $_? (simple)
by JadeNB
in thread why does push not default to $_?
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |