Syntactic Confectionery Delight | |
PerlMonks |
Question re $obj->$action(@args) syntaxby blazar (Canon) |
on Mar 21, 2007 at 12:31 UTC ( [id://605829]=perlquestion: print w/replies, xml ) | Need Help?? |
blazar has asked for the wisdom of the Perl Monks concerning the following question: First of all, let me premise that this is a "just out of curiosity kinda question". As of the Subject, if $obj holds a blessed reference, and $action is a subref, then in
the latter will be called as if it were an object method. (Similarly if instead of $obj you have a bareword, in which case it will be called like a class method.) I like to use this mechanism, sometimes, to implement callbacks. "Of course", it also works if instead of $obj you have an expression returning an object. OTOH generally wherever a variable holding a subref is used, an expression returning one (especially an anonymous sub altogether) could be used instead, but I don't think in this one: any kind of parentheses I may put around the expression would be parsed as some kind of dereferencing. Similarly, I can't hope in putting anything in ${ } beacause that is parsed as scalar dereferencing as of itself. As I said above, not that I really need this "feature", but is there a way to "inline" a subref as hinted above? Somehow it strikes me as as something that should be doable if not for anything else for completeness sake... Now, just like you can disambiguate between grouping parens and sub call's ones with a unary plus, what I want if not available in other ways, may have a syntax like the following:
Admittedly, I suppose that could make a hell to parse...
Back to
Seekers of Perl Wisdom
|
|