zoukankan      html  css  js  c++  java
  • Perl--函数引用

    函数的引用:       $ref=&func;   (func的定义在其他位置),不要(),当&func()时为执行函数,返回值再引用。
    
    当&func()时为执行函数,返回值再引用。
    
    [oracle@jhoa 3]$ cat 3.pl 
    sub generate_greeting { my($greeting) = "hello world"; 
    return sub {print $greeting;print "goodbye"}; }
    ##引用
     $rs = generate_greeting();
    print "$rs is $rs
    ";
    ##使用函数
     &$rs; 
    
    [oracle@jhoa 3]$ perl 3.pl 
    $rs is CODE(0x61c52a0)
    hello worldgoodbye[oracle@jhoa 3]$ 
    
    
    引用的使用;
    
    简单变量:$$ref  ${$ref}
    数组:@$ref @{$ref};  元素:$$ref[0]    $ref->[0];
    
    散列:%$ref  %{$ref};   元素:$$ref{‘a’} $ref->{‘a’};
    
    函数:&$ref(a,b);   $ref->(a,b)
    
    文件:$ref
    
    函数的引用:       $ref=&func;   (func的定义在其他位置),不要(),当&func()时为执行函数,返回值再引用。
    
    
    [oracle@jhoa 3]$ cat 3.pl 
    sub generate_greeting { my($greeting) = "hello world"; 
    return sub {print $greeting}; } $rs = generate_greeting();
     &$rs(); 
     &$rs; 
    
    [oracle@jhoa 3]$ perl 3.pl 
    hello worldhello world[oracle@jhoa 3]$ 
    

  • 相关阅读:
    nginx
    VSFTPD
    Dubbo
    ZooKeeper
    maven
    linux 学习
    Shiro安全框架
    Jqueryの锋利的jquery练习
    Java中的数组操作进阶
    Java IO总结之缓冲读入文件
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351960.html
Copyright © 2011-2022 走看看