in reply to Perl precedence details

Hello hurricup,

A named unary operator is a built-in function which takes exactly one argument. Examples are chdir and rand. See Named Unary Operators.

The distinction between leftward and rightward list operators is explained in Terms and List Operators (Leftward):

In the absence of parentheses, the precedence of list operators such as print, sort, or chmod is either very high or very low depending on whether you are looking at the left side or the right side of the operator. For example, in
@ary = (1, 3, sort 4, 2); print @ary; # prints 1324
the commas on the right of the sort are evaluated before the sort, but the commas on the left are evaluated after. In other words, list operators tend to gobble up all arguments that follow, and then act like a simple TERM with regard to the preceding expression.

In other words, the commas on the right of the sort are evaluated first, because the rightward aspect of the list operator sort has a lower precedence than the comma operator. But the list operator sort is evaluated before the commas to its left, because its leftward aspect has a higher precedence than the comma operator. Prototypes have nothing to do with the difference between leftward and rightward here.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Perl precedence details
by hurricup (Pilgrim) on Jun 20, 2015 at 10:07 UTC

    First, I've read perlop, thank you :)

    Second, guess, You are wrong, it's not built in function:

    use 5.010; use strict; sub mysub($) { printf "Sub called with %s\n", join '', @_; } sub mysub2 { printf "Sub2 called with %s\n", join '', @_; } mysub "test" eq "test"; mysub2 "test" eq "test";
    mysub behaves like named unary op (because of proto i belive) and mysub2 behaves like list operator without parens.

    Again, I need 100% sure explanation (not guesses) and point where I can find the list of named unary built ins without digging all the perldocs.

      Second, guess, You are wrong, it's not built in function:

      Well, yes, you’re right, it’s not only a built-in function, it’s any function, built-in or user-defined, that has a ($) prototype.

      The Camel Book (4th Edition, 2012) has a table listing “all the named unary operators” on page 106. After 88 built-ins, the final entry is:

      any ($) sub

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,