How can I dynamically include Perl modules without using eval?

前端 未结 6 1309
青春惊慌失措
青春惊慌失措 2020-11-29 03:13

I need to dynamically include a Perl module, but if possible would like to stay away from eval due to work coding standards. This works:

$module = \"My::modu         


        
6条回答
  •  清酒与你
    2020-11-29 03:27

    How about using the core module Module::Load

    With your example:

    use Module::Load;
    my $module = "My::module";
    load $module;
    

    "Module::Load - runtime require of both modules and files"

    "load eliminates the need to know whether you are trying to require either a file or a module."

    If it fails it will die with something of the like "Can't locate xxx in @INC (@INC contains: ...".

提交回复
热议问题