zoukankan      html  css  js  c++  java
  • perl 函数回调 引用$client->run(sub {$client->sync});

    匿名函数引用:
    
    [root@wx03 wx]# perl a1.pl 
    CODE(0x2077b30)
    test
    [root@wx03 wx]# cat a1.pl 
    $ref= sub {return test."
    "};
    print $ref;
    print "
    ";
    print &$ref;
    
    [root@wx03 wx]# perl a1.pl 
    CODE(0x21a2b30)
    test
    
    
    
    my $eventloop=$client->run(sub {print "test
    ";});  
    
    
    sub {print "test
    ";} 是匿名函数一个引用;
    
    [root@wx03 lib]# cat eventloop.pm 
    package eventloop;
    
    use AE;
       use AnyEvent;
    ##定义watch
        sub run {
    	my $self=shift;
           my $code=shift;
        my $t = AnyEvent->timer(
            after    => 0,
            interval => $self->{interval},
            cb       => $code
        );
        ##不要再每秒打印时间
        ##undef $t;
        my $cv = AnyEvent->condvar;
        $cv->recv;
    	};
    1;
    
    cb=> 必须是函数的引用:
    
    
    
    
    
    [root@wx03 wx]# cat scan.pl 
    use lib '/root/scanwx/lib';
    use Client;
    use Data::Dumper;
    my $client=Client->new();
    
    my $qrcode=$client->get_qrcode();
    print "$qrcode is $qrcode
    ";
    
    my $login_info=$client->login_info();
    my $login=$client->login();
    
    
    $client->run(sub {$client->sync});
    
    $str=Dumper($client);
    print "$str is $str
    "
    
    
    [root@wx03 lib]# cat sync.pm 
    package sync;
    sub sync {
       my $self=shift;
       print "test
    ";
    };
    1;
    
    
    
    
    

  • 相关阅读:
    朋友
    Music
    Rnadom Teams
    Bone Collector(01背包)
    Common Subsequence LCS
    Copying Books
    Equal Sum Sets
    Checker Challenge
    棋盘问题
    油田(Oil Deposits)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350777.html
Copyright © 2011-2022 走看看