Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Strange finish!!

by duff (Vicar)
on Nov 07, 2007 at 07:27 UTC ( #649421=note: print w/ replies, xml ) Need Help??


in reply to Strange finish!!

In Perl, semicolons are statement separators, not statement terminators. Since there is no statement after the last one in a file, a semicolon is not necessary. Same thing for the last statement in a block. Which is why your die doesn't need one. Add a statement after your die with no semicolon in between and perl will give you an error.


Comment on Re: Strange finish!!
Re^2: Strange finish!!
by narainhere (Monk) on Nov 07, 2007 at 08:17 UTC
    But duff what's the statement terminator in perl "Newline" is it???

    The world is so big for any individual to conquer

      Newlines are unnecessary, check out the Obfuscation page here!
      Following on what duff said, the "statement terminator" is either a semi-colon, end-of-block, or end-of-file. The semi-colon is actually a "statement separator", so when you want two or more statements in a perl script or block (which is just about always), you need to put semicolons between them.

      Spaces, tabs and newlines (when they are not enclosed in any sort of quotation marks) are only useful as token separators (they are often "optional" in this role). Of course, they also serve as aids to human readability, but they only have a functional syntactic role when they are required as token separators (e.g. you must have whitespace between "use" and the name of a module or pragma), and in those cases, spaces, tabs and newlines are interchangeable -- perl doesn't care what kind of whitespace you provide, so long as you put it where it's needed:

      #!/usr/bin/perl # (shebang line syntax is dictated by unix shell) use strict;use warnings;my @a = qw (1 2 3);print "@a\n"
      Perl has no statement terminator; just a statement separator.
Re^2: Strange finish!!
by Cap'n Steve (Friar) on Nov 08, 2007 at 05:10 UTC
    So is there a sensible explanation for formats or is that just considered an exception?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (14)
As of 2014-07-31 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (252 votes), past polls