Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this messageJohn 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
Post Follow-up to this messageOn 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
Post Follow-up to this messageChris 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
Post Follow-up to this message>>>>> "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 hab
it.
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
!
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.