in reply to Why is this script giving syntax errors?

Didn't you mean close FILE; in the first script (ending it with ;)? Since close FILE is the last statement in the second script, the ; is optional.

Replies are listed 'Best First'.
Re^2: Why is this script giving syntax errors?
by Old_Gray_Bear (Bishop) on Nov 02, 2013 at 21:00 UTC
    kenosis said:
    Since close FILE is the last statement in the second script, the ; is optional.
    The semi-colon is only option if it's omitted from the last line of your code. As the OP pointed out, the last line of the code doesn't stay that way for very long; there is always one more subroutine to be added.

    I view the 'optional' semi-colon the same way I view the 'optional' comma on the last item of a list. I just know that I'll want to add something else later, and since the Perl compiler is forgiving, I just add it automatically.

    Nota Bene: Just because I know that some particular piece of punctuation is optional (in the sense that the Compiler does the right thing if it is present or absent) doesn't automatically mean that I will remember when I am debugging a problem at O'Dark-Hundred with the entire site down. Don't leave land-mines lying around for the next person to stumble over two years later, it may be you....

    Update =====
    Added the quote from kenosis

    ----
    I Go Back to Sleep, Now.

    OGB

      The semi-colon is only option if it's omitted from the last line of your code.

      Perhaps I'm misunderstanding you here, but when I mentioned "statement," I (implicitly) meant a line containing a set of executable commands, since a semi-colon isn't required on any one of the last four lines of the following script:

      use strict; use warnings; print "Hello, world.\n"; # # # #

      My use of the term "statement" may not have been the best, in this context.

      Your Nota Bene bears an especially crucial message and I appreciate you adding it. Thank you, and the message is well noted.

      "The end of the script" is just part of the truth. It actually is "The end of a scope":

      $ perl -MO=Deparse -e'print $a' print $a; -e syntax OK $ perl -MO=Deparse -e'{print $a}' { print $a; } -e syntax OK $ perl -MO=Deparse -e'{print $a}print $a' { print $a; } print $a; -e syntax OK

      Enjoy, Have FUN! H.Merijn
Re^2: Why is this script giving syntax errors?
by cspctec (Sexton) on Nov 02, 2013 at 19:08 UTC
    Wow, I can't believe I missed that. It's always something small and stupid that makes you feel like an idiot for asking. Thanks to both of you.

      You're most welcome, cspctec!

      Wow, I can't believe I missed that. It's always something small and stupid that makes you feel like an idiot...

      Have been there all too often...