http://www.perlmonks.org?node_id=11130583


in reply to Checking on live site if subroutine exists

Just a minor comment about this pattern:

my $_tsub = "SendMultiPartMemberEmailMimeLiteSendGrid"; if(exists &{$_tsub}) { # code to call it } else { require "/path/to/the/file/SendMultiPartMemberEmailMimeLiteSen +dGrid.pl"; # code to call it }

Your code to call it is unnecessarily duplicated. Better:

my $_tsub = "SendMultiPartMemberEmailMimeLiteSendGrid"; if ( not exists &{$_tsub} ) { require "/path/to/the/file/SendMultiPartMemberEmailMimeLiteSen +dGrid.pl"; } # code to call it

But this can probably be even better written as:

require "/path/to/the/file/SendMultiPartMemberEmailMimeLiteSendGri +d.pl"; # code to call it

Because require is smart enough to not load the same file twice.