How does a Perl program know where to find the file containing Perl module it uses?

后端 未结 3 1184
悲&欢浪女
悲&欢浪女 2020-12-01 12:58

If my Perl program uses Perl modules, how will it determine where to find the file containing the module code?

For example, if the program contains:



        
3条回答
  •  误落风尘
    2020-12-01 13:33

    While this does not directly answer the question, here are some simple techniques to determine the full path to the module file you want to use.

    To view the default contents of the @INC array, along with lots of other info, from the command line:

    perl -V      
    

    If you want to know the location of the Carp module:

    perldoc -l Carp
    

    Inside a script, printing the contents of the %INC hash is useful to determine the actual module you are using, especially if you have modified @INC from its default:

    use Carp;
    print $INC{'Carp.pm'};
    

    This simple script can also be used to Find installed Perl modules matching a regular expression and to identify any duplicate modules in different directories.

提交回复
热议问题