in reply to Re^2: The & prototype and code references in scalars.
in thread The & prototype and code references in scalars.

We had this discussion recently¹, unfortunately you can't define a prototype which allows literal codeblocks and coderefs (resp. scalars) at the same time.

You can allow alternatives with (\[&$]) but alas there is no ([&$]) 8(

At least you can spare the curlies async \&$codeRef ; !

Cheers Rolf

¹) update see coderefs and (&) prototypes

Replies are listed 'Best First'.
Re^4: The & prototype and code references in scalars.
by BrowserUk (Patriarch) on Feb 18, 2010 at 00:17 UTC

    Thanks for the reference. I think I must have been away that day cos I do not remember that thread at all. And looking at my posting history, I didn't post anything that entire week.

    With regard to \&{ $coderef } versus \&$coderef: I discovered long ago that

    • there is no performance difference between sigil{ $scalar } & sigil$scalar;
    • and that (for example) print for @{ $_[0] } works, where print for @$_[0] doesn't.

    Hence, the 2-char longer (4 if you count my preferred whitespacing) form has no downsides and benefits from the extra clarity when the scalar being dereferenced comes from a compound source. Plus I do not have to try and remember when I have to use the longer form and when I can get away with the shorter. And I like consistency.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Well @$_[0] parses as @{$_}[0] producing an arrayslice.

      My rule is simple, better use curlies when it gets long.

      Cheers Rolf