Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: What is the difference between a Statement and an Expression?

by pmas (Hermit)
on Aug 02, 2001 at 20:37 UTC ( [id://101708]=note: print w/replies, xml ) Need Help??


in reply to What is the difference between a Statement and an Expression?

I can understand why you are confused. Here is my attempt to add light to darkness.. :)

expression is just a way to calculate a value, using operators, build-in or your own functions.
statement is more ezoteric: it may be assigment, variable declaration (my,...), subroutine call, control structures (if, while, foreach, block = {}, pragma (use...), etc.

And now, IMO what confuses you: sometimes statement might have a value like expression has, and statement can be used also as expression sometimes. Simple example:

while ($line = <>) { print $line; }
Here $line = <> is used as statement (reading a line from STDIN) and also as expression (returning value assigned to $line. String is TRUE if something (not undef) was read in, and undef is returned when End_Of_File was reached. It might be confusing for beginners, but it is extremely convenient.
You'll find many idioms like this, Larry Wall (inventor of perl) made perl so flexible, there is even abbreviation for that: TIMTOWTDI - There Is More Than One Way To Do It. Perl tries to help you. Just always  use strict and use -w switch, everything else will come along.

Your experience will grow, and your fun using perl will follow. Welcome in monastery, and come again. There is lot of information for you around.

I gave you ++ for noticing the difference.

pmas
To make errors is human. But to make million errors per second, you need a computer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://101708]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2024-04-18 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found