Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: Reference: existsChapter 5
Function Reference
Next: Reference: exp
 

exit

exit status

Exits the current Perl process immediately with that value given by status. This could be the entire Perl script you are running, or only a child process created by fork. Here's a fragment that lets a user exit the program by typing x or X:

$ans = <STDIN>;
exit 0 if $ans =~ /^[Xx]/;
If status is omitted, the function exits with 0. 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.


Previous: Reference: existsPerl in a NutshellNext: Reference: exp
Reference: existsBook IndexReference: exp

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.