Here's how I look at it...

First, a literal "counts" as a statement. You can say:

foo(); 'this is a string'; bar();

The string-as-statement doesn't do anything, but it's syntactically "correct." You could have also put a number there. I use this sometimes when I want to loop while something is true, but I don't otherwise have a loop body.

1 while ( s/^\t// );

Rather than a simple scalar as a statement, you could also have a list, delimited with commas. The list elements can be calls to subs or whatever else you might stick in a list.

# assignment @foo_and_bar = ( foo(), bar() ); # same thing, not assigned to anything foo(), bar();

There may also be a way of thinking about this that has to do with operator precedence (the comma is an operator), but I personally don't look at it that way. Having written this now, I wonder how this compares to the actual semantics. This kind of construct is one that I encounter infrequently enough that I haven't needed to know the gory details.

Update: Upon further consideration, I think all these are expressions. A sub call is an expression, a literal scalar is an expression, and a comma-separated list of expressions is an expression. You could even have two semi-colons on top of each other and make an empty expression.


In reply to Re: perl statements by kyle
in thread perl statements by neptuneray

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.