in reply to coderefs and (&) prototypes
the parser can't decide at compile-time if a scalar like $a holds a coderef, but doing the idempotent operation \& (that means reference of the dereference) makes it undoubtable for the parser.
UPDATE:
prototypes are a compile-time not run-time issue, which explains the confusion.
@JadeNB: defining your own prototype opens the oportunity to say sub f([&$]) { ... } such that at compiletime any scalar is acceptable, which can be assured at runtime to be a coderef!ยน
Cheers Rolf
UPDATE:
(1) Unfortunately this is wrong, there is no sub f([&$]) { ... } for an alternative first argument type, only sub f(\[&$]) { ... }. But this will NOT work like map() or grep(), because now the argument "absolutely must start with that character" (here & or $)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: coderefs and (&) prototypes
by JadeNB (Chaplain) on Jul 27, 2009 at 22:41 UTC | |
by LanX (Saint) on Jul 27, 2009 at 22:50 UTC |