in reply to Checking on live site if subroutine exists

You could also execute it in the context of an eval block; then have a reasonable default if it fails; even if it is to do nothing:
local $@; my $ok = eval { require q{/path/to/script.pl}; # send code to call it now that we pulled it in... 1; };
You might want to check $ok or $@. NB: I don't always test in production, but when I do; I use the block form of eval.

Replies are listed 'Best First'.
Re^2: Checking on live site if subroutine exists
by bizactuator (Sexton) on Mar 27, 2021 at 02:38 UTC
    This subroutine sends an email to a member for one they asked for, like a notice when someone they referred joins, etc.

    So, does calling it with an eval or checking if it exists actually execute it?

      > So, does calling it with an eval

      yes

      > or checking if it exists actually execute it?

      no

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      To add to what LanX said, eval effectively hides any errors that might occur when executing what's in the block.

      Since this is a .pl file and require happens at runtime, you may get away with just checking if this file contains some expected characteristics before calling require - like actually existing (or containing some expected text). That said, it's better practice to create an actual Perl module and esure it can be found via @INC (i.e., via PERLLIB, PERL5LIB, or judicious use of FindBin + use lib ....