> He hasn't had a chance to explain how that accounts for the difference in the output of scalar(($a)=5) and scalar($a=5)

OK, my interpretation: the outer parens enclose to the params passed to scalar(). Both lines evaluate the result of the assignment in scalar context.

DB<36> print scalar (($a)=5) 1 # Number of elements in list DB<37> print scalar ($a=5) 5 # value of $a
as you can see there is no measurable difference between (),(2),(1,2)
DB<41> print scalar (@a=(5,6)) 2 DB<42> print scalar (@a=(6)) 1 DB<43> print scalar (@a=()) 0
whats notable is that ($a) is evaluated like a literal array!
DB<49> print scalar ( ($a)=(5,6,7) ) 3 DB<50> print scalar ( ($a,$b)=(5,6,7) ) 3 DB<51> print scalar ( ()=(5,6,7) ) 3
AFAIR what one expect as "the scalar of a list" should be the last element and only the scalar of an array is the number of elements.

So the results prooves once again how problematic it is in perl5 to see the difference between arrays and lists!

Maybe as a rule of thumb: Lists are immutable, so what looks like "a list at the LHS" has to be an array !

Cheers Rolf


In reply to Re^14: chopping a string into slices - is there a more elegant way to do it? by LanX
in thread chopping a string into slices - is there a more elegant way to do it? by rovf

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.