$^S Current state of the interpreter. $^S State --------- ------------------- undef Parsing module/eval true (1) Executing an eval false (0) Otherwise The first state may happen in $SIG{__DIE__} and $SIG{__WARN__} handlers. #### #!/usr/bin/perl use strict; use warnings; close STDERR; $|++; my $contaerrori= 0; $SIG{__WARN__} = sub { ++$contaerrori;print STDOUT "[WARN] ",@_ }; $SIG{__DIE__} = sub { print STDOUT "[CRITICAL ERROR]\t",@_; if ($^S == 1) { print "\tPerl interpreter 1 (Executing an eval)\n\tCONTINUE RUNNING\n"} elsif ($^S == 0){ print "\tPerl interpreter 0 (Otherwise)\n\tSTOP\n"} else { print "\tPerl interpreter undef (Parsing module/eval)\n"} print "\n"; }; ################################################################################ # HERE THE TESTS ################################################################################ print "\nNATURAL END OF PROGRAM : ",$contaerrori," WARN",($contaerrori eq 1 ? '' : 'S' )," IN $0\n"; #### #A print $a."\n"; #B require AAAAAA; #C eval { require BBBBB; } or do { warn " cannot load the mobule BBBBB \$^S = $^S\n"; print "\ttrying with another module: CCCC\n\n"; eval { require CCCC; } or do {warn "cannot load the mobule CCCC \$^S = $^S\n";}; if ( $@ ) {warn "no hope with modules today..\n\n";die} else {print "\tsuccesfully loaded CCCC\n" ;} }; #D eval { 0 } or do { warn "zero is not true \$^S = $^S\n"; }; #E eval { undef } or die "undef is not enough \$^S = $^S\n"; #F eval {require AAAAAA;}; if ($@) { local $SIG{'__DIE__'} = 'DEFAULT'; die "default die : $@"; } #### #A [WARN] Use of uninitialized value in concatenation (.) or string at warn-die.pl line 18. NATURAL END OF PROGRAM : 1 WARN IN warn-die.pl #B [CRITICAL ERROR] Can't locate AAAAAA.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at warn-die.pl line 20. Perl interpreter 0 (Otherwise) STOP #C [CRITICAL ERROR] Can't locate BBBBB.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at warn-die.pl line 21. Perl interpreter 1 (Executing an eval) CONTINUE RUNNING [WARN] cannot load the mobule BBBBB $^S = 0 trying with another module: CCCC [CRITICAL ERROR] Can't locate CCCC.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at warn-die.pl line 23. Perl interpreter 1 (Executing an eval) CONTINUE RUNNING [WARN] cannot load the mobule CCCC $^S = 0 [WARN] no hope with modules today.. [CRITICAL ERROR] Can't locate CCCC.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at warn-die.pl line 23. ...propagated at warn-die.pl line 24. Perl interpreter 0 (Otherwise) STOP #D [WARN] zero is not true $^S = 0 NATURAL END OF PROGRAM : 1 WARN IN warn-die.pl #E [CRITICAL ERROR] undef is not enough $^S = 0 Perl interpreter 0 (Otherwise) STOP #F [CRITICAL ERROR]Can't locate AAAAAA.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at warn-die.pl line 25. Perl interpreter 1 (Executing an eval) CONTINUE RUNNING