Home > Archive > PERL Beginners > September 2004 > (when) is the ; required?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
(when) is the ; required?
|
|
|
| I was just updating some old script and found a big switch full of
one-liners. In one of the cases there is no ";". Why doesn't the
interpreter flag that as a syntax error?
| |
| Gunnar Hjalmarsson 2004-09-30, 2:55 am |
| John wrote:
> I was just updating some old script and found a big switch full of
> one-liners. In one of the cases there is no ";". Why doesn't the
> interpreter flag that as a syntax error?
The ';' character separates statements within a block. Accordingly,
it's not needed after the last statement.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Chris Devers 2004-09-30, 2:55 am |
| On Thu, 30 Sep 2004, Gunnar Hjalmarsson wrote:
> The ';' character separates statements within a block. Accordingly,
> it's not needed after the last statement.
That said, it's a good habit to include it. If you ever come back to
edit that file later, the original last statment might not always be the
last statement, and if you forget to add it -- which would be all too
easy to do -- then things will break.
My impression is that the missing semi-colon is allowed to make it so
that statements like this --
sub ack { print "Ack! Ack! Mars will rule!" }
-- work as one-liners without having to fuss over another semi-colon.
For anything longer than a single-statement one-liner, it's a bad habit.
IMO.
--
Chris Devers
| |
| Gunnar Hjalmarsson 2004-09-30, 2:55 am |
| Chris Devers wrote:
> Gunnar Hjalmarsson wrote:
>
> That said, it's a good habit to include it. If you ever come back
> to edit that file later, the original last statment might not
> always be the last statement, and if you forget to add it -- which
> would be all too easy to do -- then things will break.
Agreed. (I confined myself to give a plausible explanation to the OP's
observation.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
| |
| Randal L. Schwartz 2004-09-30, 11:24 am |
| >>>>> "Chris" == Chris Devers <cdevers@pobox.com> writes:
Chris> My impression is that the missing semi-colon is allowed to make it so
Chris> that statements like this --
Chris> sub ack { print "Ack! Ack! Mars will rule!" }
Chris> -- work as one-liners without having to fuss over another semi-colon.
Chris> For anything longer than a single-statement one-liner, it's a bad habit.
My rule is that if I'm writing a multi-line block:
if (...) {
...
...
...
}
then I include the final semicolon, but if it's only one line,
I leave it off.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
|
|
|
|
|