in reply to Re: Re: Re: Extract potentially quoted words
in thread Extract potentially quoted words

To quote perlsyn.pod:

The only kind of simple statement is an expression evaluated for its side effects.

Take a random Perl script you have lying about somewhere. Most of the statements in that code will likely be simple statments, that is, just an expression. Such statements can be used as expressions since they are, um, just "an expression evaluated for its side effects". You could put "my @value=" in front of it to demonstrate that fact and most of the time you end up with valid Perl code.

There are lots of times where I take code that was a statement and rework code around such that I'm now using that statement as an expression (for example, by moving it into the condition of an if or while).

But if you have a statement that isn't so simple, moving into a "context" where an expression is required will probably get you a syntax error.

        - tye (but my friends call me "Tye")
  • Comment on (tye)Re2: Extract potentially quoted words

Replies are listed 'Best First'.
Re: (tye)Re2: Extract potentially quoted words
by merlyn (Sage) on Jun 07, 2001 at 02:55 UTC
    Right, but EXPR is an expression, and "EXPR;" is a statement. In loose terminology, you could call the latter "an expression", but it isn't. It's a statement that contains an expression that has a side effect.

    And adding "my @value =" is not adding it to the statement... it's adding it to the expression part of the statement.

    I'll repeat what I said in the chatterbox. In Perl, you have statements, and you have expressions. They are not at the same level in the syntax tree, and you cannot ever substitute one for the other. Your examples above do not show that yet.

    -- Randal L. Schwartz, Perl hacker

      As I already said in chatter, the semicolon in Perl is a statement separator not a statement terminator (unlike in C). So the semicolon is not a part of the statement.

              - tye (but my friends call me "Tye")
        If it was only a statement separator, then either this should be legal:
        $a = 3 # no semi needed here if ($a == 5) { print "b" }
        Or this should be illegal:
        if ($a == 5) { print "b" } if ($b == 2) { print "c" }
        Because if we need it as a separator, how come we don't need it consistently for those?

        No, the current syntax mimics C syntax, where an expression is not a statement, but an expression followed by a semicolon is indeed a statement. Too bad that the terminology has gotten muddled somewhere, but Perl acts according to this definition regardless of how the manpages read.

        -- Randal L. Schwartz, Perl hacker