p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Perl (http://p2p.wrox.com/forumdisplay.php?f=196)
-   -   'exit;' have to be the last line in every script (http://p2p.wrox.com/showthread.php?t=50269)

crmpicco November 14th, 2006 07:50 AM

'exit;' have to be the last line in every script

Does the line 'exit;' have to be the last line in every Perl script?


ciderpunx November 14th, 2006 11:36 AM

Nope. Give it a try!

Don't Stand on your head - you'll get footprints in your hair

crmpicco March 16th, 2007 08:54 AM

yep, you're right. cheers....

exit Evaluates EXPR and exits immediately with that value. (Actually, it calls any defined END routines first, but the END routines may not abort the exit. Likewise any object destructors that need to be called are called before exit.) Example:

    $ans = <STDIN>;
    exit 0 if $ans =~ /^[Xx]/;

See also die(). If EXPR is omitted, exits with 0 status. The only universally portable values for EXPR are 0 for success and 1 for error; all other values are subject to unpredictable interpretation depending on the environment in which the Perl program is running.

You shouldn't use exit() to abort a subroutine if there's any chance that someone might want to trap whatever error happened. Use die() instead, which can be trapped by an eval().


All times are GMT -4. The time now is 07:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.