Auto die on failed sys calls?

J

J Krugman

Is there any way to instruct perl to die whenever a system call
(e.g. through open, opendir, backticks, system, etc.) fails?

The aim is to be able to enclose a series of such calls in a single
eval block, and catch any failures at the end, instead of checking
for them after each system call.

Thanks!

jill
 
A

Anno Siegel

J Krugman said:
Is there any way to instruct perl to die whenever a system call
(e.g. through open, opendir, backticks, system, etc.) fails?

No, there isn't.

Note also that open and opendir belong in a different category than
backticks and system. The first ones call kernel- or library routines,
the second ones call external programs.

The aim is to be able to enclose a series of such calls in a single
eval block, and catch any failures at the end, instead of checking
for them after each system call.

One could think of tie-ing $! so that it dies when something non-zero
is stored there, but that doesn't work either. The values in $! get
there via magic, not the standard SV procedure, so the tie is ignored.

Anno
 
J

John W. Krahn

J said:
Is there any way to instruct perl to die whenever a system call
(e.g. through open, opendir, backticks, system, etc.) fails?

The aim is to be able to enclose a series of such calls in a single
eval block, and catch any failures at the end, instead of checking
for them after each system call.

perldoc Fatal


John
 
J

John W. Krahn

Anno said:
Ah... interesting. Thanks for mentioning it, I never noticed that
module.

You learn something new every day. :) At least I know I do.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top