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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Special die

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
0
0
GB
I want to abort some scripts under certain error conditions, without printing to STDERR.

I have script A requiring script B.
Script A calls parseFile() defined in script B.
I would like parseFile to have the following functionality
Code:
if (error==1)
{
  logError(....); #defined in logging.pl (required by script B)
  die withouting printing to STDERR
}

unforatunately, even without passing in a string to die, it will print "died at line xxx" to STDERR!

Is there any thing else I could do to abort more gracefully please? As I have by own logging facility already.

Ta
 
Try "exit(0)". That will end the current perl program and all calling perl program (i.e. exit back to the OS). Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi.

die "\n" should die without giving the extraneous output. You can also give something like:

die "Parsing failed\n"

You will get the message parsing failed, but will not get the "died at line nnn" kind of output.

HTH.
 
"perldoc -f die" says this:

die LIST
Outside an `eval', prints the value of LIST to
`STDERR' and exits with the current value of `$!'
(errno). If `$!' is `0', exits with the value of
`($? >> 8)' (backtick `command` status). If `($?>> 8)' is `0', exits with `255'. Inside an
`eval(),' the error message is stuffed into `$@'
and the `eval' is terminated with the undefined
value. This makes `die' the way to raise an
exception.

So, you should be able to do something like this:

eval {
if (error==1) {
logError(....);
die "Parsefile error"; ### The die message
### populates variable $@
}
};
if ($@) {
### The die is caught here since the die message
### populated $@ - you can either
### choose to print something, or just exit.
exit 0;
}

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
You're making things way too complicated. If you don't want any output and you want the program to abort just use exit instead of die! That's all it takes!
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top