in reply to Re^2: why does push not default to $_? (simple)
in thread why does push not default to $_?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: why does push not default to $_? (simple)
by LanX (Saint) on Dec 05, 2008 at 22:59 UTC | |
by LanX (Saint) on Dec 06, 2008 at 02:00 UTC | |
by JadeNB (Chaplain) on Dec 07, 2008 at 18:13 UTC | |
by ikegami (Patriarch) on Dec 07, 2008 at 19:04 UTC | |
by LanX (Saint) on Dec 07, 2008 at 19:45 UTC |