[sf-perl] dynamic use command

Stephen Nelson stephenenelson at mac.com
Thu Apr 3 18:32:27 PDT 2008


I think you meant

eval("use Net::SMTP::SSL");

if ($@) {
     print "$net_smtp_ssl is missing\n";
     exit;
}


Otherwise I suspect it'll just do the block eval and evaluate the string.

Randy J. Ray wrote:
> I've had this happen before, too. What you need to do is wrap the whole 
> statement in a string:
>
> eval {
>      "use Net::SMTP::SSL";
> };
>
> if ($@) {
>      print "$net_smtp_ssl is missing\n";
>      exit;
> }
>
> You don't actually need the second "use". The code is now loaded and available 
> to you. By using the eval, you have kept the application from stopping in the 
> event that the module isn't available.
>
> Randy
>   



More information about the SanFrancisco-pm mailing list