<?xml version="1.0" encoding="windows-1252"?>
<node id="101603" title="Re: What is the difference between a Statement and an Expression?" created="2001-08-02 07:17:28" updated="2005-07-30 14:06:43">
<type id="11">
note</type>
<author id="3607">
Petruchio</author>
<data>
<field name="doctext">
If I am off the mark, here, I trust our local computer 
scientists will set me straight.
&lt;p&gt;
Quoth the Camel's glossary:
&lt;p&gt;
&lt;hr&gt;
&lt;b&gt;expression&lt;/b&gt;&lt;br&gt;
Anything you can legally say in a spot where a &lt;i&gt;value&lt;/i&gt; 
is required.  Typically composed of 
&lt;i&gt;literals, variables, operators, functions,&lt;/i&gt; and 
&lt;i&gt;subroutine&lt;/i&gt; calls, not necessarily in that order.
&lt;p&gt;
&lt;b&gt;statement&lt;/b&gt;&lt;br&gt;
A &lt;i&gt;command&lt;/i&gt; to the computer about what to do next, 
like a step in a recipe:  "Add marmalade to batter and 
mix until mixed."  A statement is distinguished from a 
&lt;i&gt;declaration&lt;/i&gt;, which doesn't tell the computer to 
do anything, but just to learn something.
&lt;hr&gt;
&lt;p&gt;
Similarly, Barron's &lt;i&gt;Dictionary of Computer and 
Internet Terms&lt;/i&gt; says an expression is a series of 
symbols that can be evaluated to have a particular 
value, while a statement is a single instuction in 
a computer language.
&lt;p&gt;
In your example, then, &lt;code&gt;1+1&lt;/code&gt; is actually
the expression; it's not much of a statement, since
it (normally) doesn't tell Perl to do anything
meaningful.
&lt;p&gt;
&lt;code&gt;$x = 1+1&lt;/code&gt; is a statement, if you terminate 
it with a semicolon. It tells Perl to do something... 
evaluate the expression &lt;code&gt;1+1&lt;/code&gt; and assign 
the result to $x.
&lt;p&gt;
It's not actually quite as clear cut as that, however. 
For instance, I believe &lt;code&gt;1+1&lt;/code&gt; can qualify as 
a statement, as when you use it thus:
&lt;p&gt;
&lt;code&gt;
print two(),"\n";
sub two { 
  1+1
}
&lt;/code&gt;
&lt;p&gt;
Here it's telling Perl that the return value of &amp;two 
should be 2. Likewise, &lt;code&gt;$x = 1+1&lt;/code&gt; can be 
used as an expression:
&lt;p&gt;
&lt;code&gt;perl -e 'print "Yup\n" if $x = 1+1;'&lt;/code&gt;
&lt;p&gt;
Here &lt;code&gt;$x = 1+1&lt;/code&gt; is used as an expression, 
with the conditional depending on its return value 
(which happens to be 2).
&lt;p&gt;
If this seems vague, remember that these terms are 
for your use, to help you express yourself. Whether 
you choose to call &lt;code&gt;$x = 1+1&lt;/code&gt; a statement 
or an expression tells us something of the way you're 
regarding it in the present context.</field>
<field name="root_node">
101594</field>
<field name="parent_node">
101594</field>
</data>
</node>
