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

$obj->$action(@args);

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:

$obj->+(EXPR)(@args);

Admittedly, I suppose that could make a hell to parse...


In reply to Question re $obj->$action(@args) syntax by blazar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.