in reply to array assignment with list operator , no parenthesis

As for why Perl has this little wart, it's because assigning a literal list to an array like that less common than saving the return value of a function for which you omit the parens. You can safely do this:
$text = join "|", 1, 2, 3;
but if assignment bound tighter than comma, that would annoyingly parse as:
($text = join "|"), 1, 2, 3;

Replies are listed 'Best First'.
Re^2: array assignment with list operator , no parenthesis
by ikegami (Patriarch) on May 14, 2007 at 14:45 UTC

    I'm not sure where you are going, but it seems the conclusion would be that
    my @one = 7,2,3;
    is
    my @one = (7,2,3);
    because
    (my @one = 7),2,3;
    would be annoying.

    The very post to which you replied shows this is untrue.
    my @one = 7,2,3;
    is the same as
    (my @one = 7),2,3;

    There is more than one operator represented by the comma. Your examples and therefore your conclusion are irrelevant to the OP's problem since you're not using the same operator. The OP's problem is that he used the comma operator where he wanted to use the list seperator, not one of precedence.

    Just like join forced a list in your example, the OP can force a list by adding parens around the would-be list. The parens do not change the precendence in this case. They change the parsing context, causing the comma to be parsed as a different operator.

    Update: Changed wording.
    Update: s/context/parsing context/, in response to shmem's reply.

      Not (quite) accurate. Consider
      ($foo) = (7,2,4); # list context - comma := list separator print $foo,"\n"; __END__ 7
      $foo = (7,2,4); # scalar context despite of parens - comma := 'C' co +mma print $foo,"\n"; __END__ 4
      $foo = (7,2,4) x 3; # comma := 'C' comma, 'x' operates on scalar print $foo,"\n"; __END__ 444
      @foo = (7,2,4) x 3; # comma := list separator, 'x' operates on list print @foo,"\n"; __END__ 724724724

      Parens are just grouping, thus for precedence. They do not provide list context. The list context in

      @foo = (7,2,4);

      is enforced by the LHS of the expression. But it is perfectly legal to assign a single scalar to an array. The parens are for precedence first, and then, that being clear, the comma is disambiguated as a list separator, as enforced by the LHS.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

        I was refering to the parsing context (building a block vs building a list), not the return context (list vs scalar).