zdm has asked for the wisdom of the Perl Monks concerning the following question:

Does anybody can explain why "require BB;" in 1.pl don't work in this case:

--------------------------------- file 1.pl
#!/usr/bin/env perl use 5.18.2; $SIG{__WARN__} = sub { say qq{WARN: $_[0]}; require BB; }; require AA; 1; __END__
--------------------------------- file AA.pm
package AA; use warnings; a b sub aa { my $self = shift; return $self; } 1; __END__
--------------------------------- file BB.pm
package BB; print qq{BB required\n}; 1; __END__
If I change "a b" in AA.pm to something else, which also generates warning (for example "a b c") - everything works as expected - BB.pm successfully required from $SIG{__WARN__} in 1.pl.

Replies are listed 'Best First'.
Re: Unexpected compiler behavior
by Anonymous Monk on Feb 27, 2014 at 01:15 UTC

    Does anybody can explain why "require BB;" in 1.pl don't work in this case:

    the %SIG documentation warns/cautions you against compling perl code (by calling require) from inside the handler ... don't use require (eval) or do(eval) or string eval(eval) inside a signal handler

    Whatever you're trying to solve, there is probably a better way to solve

      Thanks, now it's clear for me.
Re: Unexpected compiler behavior
by LanX (Saint) on Feb 27, 2014 at 01:10 UTC
    you should be more specific about "what doesn't work"

    both versions are identical for me and break b/c of compilation errors.

    some suggestions

    1. consider a block eval around require
    2. using heavy commands like require within an exception (which can be interrupted again while being executed) is maybe not smartest idea

    Cheers Rolf

    ( addicted to the Perl Programming Language)