duelafn has asked for the wisdom of the Perl Monks concerning the following question:
I Must have some crazy silly mistake in my code or my understanding. I don't quite get my expected output from the following very short script.
### die.pl #!/usr/bin/perl use strict; use warnings; $SIG{__DIE__} = sub { print "In die: '@_'"; }; print "Hello!\n"; die "Hi"; print "Goodbye!\n"; ### Result: [duelafn@teckla]$ ./die.pl Hello! In die: 'Hi at ./die.pl line 6. Hi at ./die.pl line 6. '[duelafn@teckla]$
Two things did not happen as expected. First, I expected execution to continue to print "Goodbye!\n";. Second, I don't get where the double message is coming from.
Any ideas or suggestions?
Update: Missed the inability to cheat death. Thanks! Any thoughts on the double message? - both messages appear between my single quotes!
Update 2: Nevermind, figured out the double message. Quotes are in the right place if I disable buffering $| = 1. Thanks all!
Good Day,
Dean
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $SIG{__DIE__} not working as expected
by pc88mxer (Vicar) on Jun 09, 2008 at 00:29 UTC | |
by educated_foo (Vicar) on Jun 09, 2008 at 01:06 UTC | |
|
Re: $SIG{__DIE__} not working as expected
by ferreira (Chaplain) on Jun 09, 2008 at 00:37 UTC |