匿名函数引用: [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;