Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Strange finish!!

by duff (Parson)
on Nov 07, 2007 at 07:27 UTC ( [id://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.

Replies are listed 'Best First'.
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?
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

      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"
      Newlines are unnecessary, check out the Obfuscation page here!
      Perl has no statement terminator; just a statement separator.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-03-28 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found