in reply to Re^4: wantarray - surprise behaviour
in thread wantarray - surprise behaviour

I've seen this said before, but

P:\test>perl -MO=Deparse -e"@a = 1,2,3,4,5; print @a" @a = 1, '???', '???', '???', '???'; print @a; -e syntax OK P:\test>perl -e"@a = 1,2,3,4,5; print @a" 1 P:\test>perl -MO=Deparse -e"@a = (1,2,3,4,5); print @a" @a = (1, 2, 3, 4, 5); print @a; -e syntax OK P:\test>perl -e"@a = (1,2,3,4,5); print @a" 12345

Empirically, that suggests that the parens are, at least in some cases, required to build a list.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^6: wantarray - surprise behaviour
by Anonymous Monk on Sep 01, 2004 at 14:51 UTC
    But they don't create lists. They are 'required' just as they are in some cases required to call a function correctly. That doesn't mean parens call functions. In the case you describe, parentheses are used for precedence:
    perl -MO=Deparse,-p -e"@a = 1,2,3,4,5; print @a" ((@a = 1), '???', '???', '???', '???'); print(@a); -e syntax OK
    A list is still created - it's just not the list you want.

      Which goes to demonstrate that saying that , and => builds lists is not enough.

      Just as parens are often required to clarify the programmers intent, so mentioning parens, and precedence is required to clarify the language's definition of a list.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon