zoukankan      html  css  js  c++  java
  • @EXPORT 和@EXPORT_OK区别

    [root@node01 lib]# cat Pk01.pm 
    package Pk01;
    require Exporter;
    @ISA = qw(Exporter);
    @EXPORT_OK = qw(munge frobnicate);  # symbols to export on request
    sub munge{
        my $a=shift;
        my $b=shift;
        return $a+$b;
    };
    sub frobnicate{
        my $a=shift;
        my $b=shift;
        return $a*$b;
    };
    
    1;
    [root@node01 lib]# cat a1.pl 
    use Pk01 qw(munge frobnicate);
    print munge(22,33);
    print "
    ";
    print frobnicate(22,33);
    print "
    ";
    [root@node01 lib]# perl a1.pl 
    55
    726
    
    
    此时都正常输出:
    
    
    
    
    [root@node01 lib]# cat a1.pl 
    use Pk01;
    print munge(22,33);
    print "
    ";
    print frobnicate(22,33);
    print "
    ";
    [root@node01 lib]# perl a1.pl 
    Undefined subroutine &main::munge called at a1.pl line 2.
    
    
    这个导致Perl来加载你的模块 但是不导入任何符号表  
    
    
    
    [root@node01 lib]# cat Pk01.pm 
    package Pk01;
    require Exporter;
    @ISA = qw(Exporter);
    @EXPORT = qw(munge frobnicate);  # symbols to export on request
    sub munge{
        my $a=shift;
        my $b=shift;
        return $a+$b;
    };
    sub frobnicate{
        my $a=shift;
        my $b=shift;
        return $a*$b;
    };
    
    1;
    [root@node01 lib]# cat a1.pl 
    use Pk01;
    print munge(22,33);
    print "
    ";
    print frobnicate(22,33);
    print "
    ";
    [root@node01 lib]# perl a1.pl 
    55
    726
    
    @EXPORT 这个导入所有的符号从YourModule's @EXPORT 到你的名字空间

  • 相关阅读:
    如何让WPF程序用上MVVM模式
    wpf开源界面收集
    WPF界面框架的设计
    WPF数据验证
    WPF实用知识点
    wpf的MVVM框架
    数据库中树形结构的表的设计
    ASP.NET MVC 分部视图
    好用的 Visual Studio插件
    ASP.NET MVC3中Controller与View之间的数据传递总结
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349454.html
Copyright © 2011-2022 走看看