I confess that I was (for reasons unknown) expecting 'x' to do listy things in List Context and scalary things otherwise

I recall the developers of Perl a bit ashamed of that one. I don't know if it was done that way for backwards compatibility or if it was simply a case of the consequences not being anticipated. It really does break the mold.

Similarly, of course, foreach VAR (LIST) BLOCK reenforces the feeling that '()' have something to do with the making of lists.

Really?

for (foo()) { bar() } # List while (foo()) { bar() } # Scalar if (foo()) { bar() } # Scalar print(foo()) # List length(foo()) # Scalar

I even use for as a topicalizer regularly.

for ($var) { # Scalar s/^/[/; s/$/]/; }

The purpose of parens in flow control statements in Perl5 is purely decorative. However, their roots are in C, where their purpose is for precedence.


In reply to Re^9: chopping a string into slices - is there a more elegant way to do it? by ikegami
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.