Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

terminate program

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How do I end my perl script in the middle, if I check and see the input is wrong and i want to end the program

like exit(1); in C
 
pretty simple....


#!/usr/local/bin/perl
if (some condition) { exit; }

or, if you would like to print to STDOUT on the way out
#!/usr/local/bin/perl
if (some condition) { die "Failed the condition\n"; }

# you often use die to get out after failure to do something you
# needed to do, like open a file
#!/usr/local/bin/perl
open(IPF,&quot;<input_File_name&quot;) or die &quot;Failed to open input file, $!\n&quot;;

'hope this helps.




keep the rudder amid ship and beware the odd typo
 
yup. Sure does. Thanks.




keep the rudder amid ship and beware the odd typo
 
Note: because die prints to STDERR and not STDOUT, if you are using it in a cgi script whatever you print that way will usually NOT show up! My solution was to write a CgiError subroutine which takes an error message and prints an html page showing the error message and then exits. This achieves the same end, but allows you to display the error in the browser.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top