Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Getting the Behavior of the "file open or die" Pragma but with a Program Pause

by davido (Cardinal)
on Oct 10, 2016 at 16:17 UTC ( [id://1173666]=note: print w/replies, xml ) Need Help??


in reply to Getting the Behavior of the "file open or die" Pragma but with a Program Pause

This is a global problem -- not just specific to the "open or die" situation you mentioned in your post. If you wish to solve it in a way that makes any calls to die result in a wait period, you may consider overriding CORE::GLOBAL::die. In this case, you would probably want to inject your wait for enter logic into CORE::GLOBAL::die, after dumping $@ to STDERR, and then exit with a non-zero exit status. brian_d_foy has a nice writeup on overriding CORE::GLOBAL::die.

Additionally, if the "print and wait for diamond operator" idiom feels too clunky, you could:

require ExtUtils::MakeMaker; ExtUtils::MakeMaker::prompt('Please hit enter to exit.', '');

...which encapsulates the ugliness in prompt, from the core module ExtUtils::MakeMaker. The advantage to using prompt is that it also quietly accepts the "default" (ie, doesn't block) if the script is run in a non-TTY environment.


Dave

Replies are listed 'Best First'.
Re^2: Getting the Behavior of the "file open or die" Pragma but with a Program Pause
by perldigious (Priest) on Oct 10, 2016 at 16:46 UTC

    Thanks davido, that's a wealth of information and suggestions. I even think I understand everything in the brian_d_foy writeup, at least until the last bit regarding objects. I've never diddled with the perl iternals, but what he describes doesn't seem overly complicated.

    I may fiddle a bit and try some things as you suggested (I've never tried prompt either), and then decide if I want to change from my current subroutine kludge. Thanks again.

    I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
    I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found