Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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?

Report this thread to moderator Post Follow-up to this message
Old Post
John
09-30-04 07:55 AM


Re: (when) is the ; required?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
09-30-04 07:55 AM


Re: (when) is the ; required?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
09-30-04 07:55 AM


Re: (when) is the ; required?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
09-30-04 07:55 AM


Re: (when) is the ; required?
>>>>> "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
!

Report this thread to moderator Post Follow-up to this message
Old Post
Randal L. Schwartz
09-30-04 04:24 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:44 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.