You'll get the same value assigned to "$s" whether you use parentheses or not.

Sorry, but that's not correct, as choroba showed in his update shortly after posting. The reason is that assignment has slightly higher precedence than the comma.

$ perl -le 'my $s = ("111","bbb"); print $s' bbb $ perl -le 'my $s = "111","bbb" ; print $s' 111 $ perl -MO=Deparse,-p -e 'my $s = ("111","bbb")' (my $s = ('???', 'bbb')); $ perl -MO=Deparse,-p -e 'my $s = "111","bbb" ' ((my $s = '111'), '???');
it will also warn you that the first 3 items are ignored

You get those warnings with commas as well - but it's a good point, since it hints that the OP may not be using warnings. fgg1991: Always Use strict and warnings!

$ perl -wMstrict -e 'my $s = ("111","222","aaa","bbb")' Useless use of a constant ("111") in void context at -e line 1. Useless use of a constant ("222") in void context at -e line 1. Useless use of a constant ("aaa") in void context at -e line 1. $ perl -wMstrict -e 'my $s = "111","222","aaa","bbb" ' Useless use of a constant ("222") in void context at -e line 1. Useless use of a constant ("aaa") in void context at -e line 1. Useless use of a constant ("bbb") in void context at -e line 1.

In reply to Re^2: The behavior when assigning an array to scalar? by haukex
in thread The behavior when assigning an array to scalar? by fgg1991

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.