juo has asked for the wisdom of the Perl Monks concerning the following question:

How can I exit a Perl script without looking at any code in the perl script after I have placed an exit. I tried exit; but it still looks at the code after my exit and gives error messages. Pieter
  • Comment on How to exit a perl script without looking anything after it

Replies are listed 'Best First'.
Re: How to exit a perl script without looking anything after it
by Blue (Hermit) on Jan 23, 2001 at 16:42 UTC
    If you have code that you'd like the program to ignore, put it after a __END__. That tells Perl that there is no more code after that.

    =Blue
    ...you might be eaten by a grue...

Re: How to exit a perl script without looking anything after it
by davorg (Chancellor) on Jan 23, 2001 at 15:38 UTC

    What do you mean by 'looks at'?

    Are you trying to prevent some code from being compiled? In that case you can't do it using exit as Perl compiles the whole file before executing it.

    Perhaps you could comment out the code that you don't want compiled? Using =pod ... =cut is a good way to comment out large chunks of code.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: How to exit a perl script without looking anything after it
by azatoth (Curate) on Jan 23, 2001 at 15:35 UTC
    Well, If you're looking to put stops in the code that will exit after an "error", you can use the die command.
    open(FH,"log.log") || die "Cannot open log.log : $!\n";
    After looking at your other question, and trying to answer it, I would suggest reading "Learning Perl, 2nd Edition".

    Go to www.oreilly.com and check it out.

    Remember : Always search the perlmonks.org site for keywords before asking a question. If you don't find it here, try www.google.com. If you don't find it there, ask away. :)

    Azatoth a.k.a Captain Whiplash

    Get YOUR PerlMonks Stagename here!
Re: How to exit a perl script without looking anything after it
by dsb (Chaplain) on Jan 23, 2001 at 21:21 UTC
    You probably want to try commenting said code out. The interpreter will compile any code it finds. As far as Perl knows, your exit could be on only one branch of a conditional statement. POD format commenting is a good way to comment out large chunks of code. -kel