Professional Web Applications Themes

(when) is the ; required? - PERL Beginners

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

  1. #1

    Default (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?
    John Guest

  2. #2

    Default Re: (when) is the ; required?

    John wrote: 

    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
    Gunnar Guest

  3. #3

    Default Re: (when) is the ; required?

    On Thu, 30 Sep 2004, 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.

    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
    Chris Guest

  4. #4

    Default Re: (when) is the ; required?

    Chris Devers 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.[/ref]

    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
    Gunnar Guest

  5. #5

    Default Re: (when) is the ; required?

    >>>>> "Chris" == Chris Devers <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
    <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!
    Randal Guest

Similar Threads

  1. Help Required
    By 4BRUCE1 in forum Macromedia Flash Player
    Replies: 2
    Last Post: October 27th, 03:29 PM
  2. Help Required
    By Dinesh Upare in forum ASP.NET Security
    Replies: 6
    Last Post: May 3rd, 12:35 AM
  3. ASP help required please
    By Stephen in forum ASP Components
    Replies: 4
    Last Post: February 25th, 01:06 PM
  4. Help required please!
    By Alex Cotgreave in forum Adobe Photoshop Elements
    Replies: 0
    Last Post: July 9th, 01:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139