关于下面的代码,$one_sub 和 $two_sub 如何成为命名子“sup”中匿名子程序的代码引用?命名的 sub 不会“返回”那两个匿名 subs;是吗? (至少我没有放过这样的声明)。
sub sup {
my $neh = sub {
say "this is 'neh' subroutine"
};
my $hen = sub {
say "this is 'hen' subroutine"
};
($neh, $hen);
}
my ($one_sub, $two_sub) = ⊃
使用 Data::Dumper::Streamer 显示:
$CODE1 = sub {
use warnings;
use strict;
no feature;
use feature ':5.10';
say q[this is 'neh' subroutine];
};
$CODE1 = sub {
use warnings;
use strict;
no feature;
use feature ':5.10';
say q[this is 'hen' subroutine];
};
最佳答案
引用perlsub :
If no
return
is found and if the last statement is an expression, its value is returned.
($neh, $hen);
是一个表达式。在列表上下文中,它的值为 2 个匿名订阅者。
关于命名子例程中的 perl 匿名子例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31053140/