zoukankan      html  css  js  c++  java
  • Perl中的@INC 及引用pm顺序

    Perl中的@INC变量用于指定Perl module的查找路径。

    如:

    $VAR1 = '../lib';
    $VAR2 = '/opt/perl/lib/5.8.3/sun4-solaris-thread-multi';
    $VAR3 = '/opt/perl/lib/5.8.3';
    $VAR4 = '/opt/perl/lib/site_perl/5.8.3/sun4-solaris-thread-multi';
    $VAR5 = '/opt/perl/lib/site_perl/5.8.3';
    $VAR6 = '/opt/perl/lib/site_perl';
    $VAR7 = '.'

    此时,如果当前路径下有一个a.pm包,而且'/opt/perl/lib/site_perl/5.8.3'下也有同名包,则'/opt/perl/lib/site_perl/5.8.3/a.pm'会被真正引用。

    有时这种行为会不合预期。

    这种情况一般可以通过调整@INC中变量顺序进行处理。

    用如下语句:

    use  lib "path";
    

     会将Path中的路径置于@INC的项端。

    如加入lib "../lib"语句后,结果如下

    $VAR1 = '/opt/perl/lib/5.8.3/sun4-solaris-thread-multi';
    $VAR2 = '/opt/perl/lib/5.8.3';
    $VAR3 = '/opt/perl/lib/site_perl/5.8.3/sun4-solaris-thread-multi';
    $VAR4 = '/opt/perl/lib/site_perl/5.8.3';
    $VAR5 = '/opt/perl/lib/site_perl';
    $VAR5 = '.';
    

      

  • 相关阅读:
    Palindrome Partitioning
    Minimum Path Sum
    Maximum Depth of Binary Tree
    Minimum Depth of Binary Tree
    Unique Binary Search Trees II
    Unique Binary Search Trees
    Merge Intervals
    Merge Sorted Array
    Unique Paths II
    C++ Primer Plus 笔记第九章
  • 原文地址:https://www.cnblogs.com/vigarbuaa/p/2660074.html
Copyright © 2011-2022 走看看