in reply to scalar in list context

You seem to believe that parens force list context. That's wrong, parens do only group and influence precedence (with the exception of the empty list).

A scalar is technically just a one element list.

There is no functional² difference between @list= (1) and @list=1 or between @list= (1,2,3,4);¹ and @list=(1,(2,3,(4)));

It's the comma operator which builds the list value (in list context).

Cheers Rolf

UPDATE: ¹)Parens corrected, THX chromatic! :)

Added second example.

²) Ikegami pointed out in a /msg that different grouping force different optrees, but of course the result is here the same...

Replies are listed 'Best First'.
Re^2: scalar in list context
by chromatic (Archbishop) on Jan 26, 2010 at 23:00 UTC
    There is no difference between @list= 1,2,3,4; and @list=(1,(2,3,(4)));

    Careful! Precedence makes a big difference between those two. You're thinking of @array = (1, 2, 3, 4) versus @array = (1, (2, 3, (4))).

      Wow thanks a lot.

      Indeed, the = has a higher precedence than comma ...

      UPDATE: what I really wanted to show is that  sub list1 { 1,2,3,4 } and  sub list2 { (1,(2,3,(4))) } return the same result. The parens are not necessary to produce a list but are saver and often better to read...

      Cheers Rolf