Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Prototype questionby rovf (Priest) |
on Sep 05, 2012 at 12:02 UTC ( [id://991819]=perlquestion: print w/replies, xml ) | Need Help?? |
rovf has asked for the wisdom of the Perl Monks concerning the following question: UPDATE: Forget this node. I just saw that I have misread the docs. NO NEED TO RESPOND. I have a sub which expects one or more arguments. In particular, the first argument could be (for instance) a number or a reference to an anonymous sub. Here are two valid examples for calling my function:
As syntactic sugar, I would like to have the possibility to specify the first argument as a code block, i.e. I guess there is no alternative for using prototypes in this case.... However, I can not specify the prototype as f(&;@), since in this case the first argument must be a sub ref or code block, but in my case, it might also be a non-reference. Hence I tried to prototype my function like this: I.e. a simple scalar or a code block, optionally followed by other arguments. Unfortunately this does not work. When invoking f as f(1,2,3,4), I get the error message Type of arg 1 to main::f must be one of [$&] (not constant item). What am I doing wrong? I must misunderstand the explanations in perlsub about the the "\[]" notation prototype somehow...
-- Ronald Fischer <ynnor@mm.st>
Back to
Seekers of Perl Wisdom
|
|