我有以下子程序:Perl中使用CODEREF作爲參數傳遞給子程序
sub my_sub {
my $coderef = shift;
$coderef->();
}
sub coderef {
my $a = shift;
my $b = shift;
print $a+$b;
}
,並要撥打my_sub(\coderef($a,$b))
以這種方式,即我想提供與它的代碼裁判的爭論和對my_sub運行功能。是否有可能在Perl中做這樣的事情?
除了作爲非描述性的名稱,'$了'和'$ B'是[專用包變量](http://perldoc.perl.org/perlvar.html#$a)與'sort'一起使用,所以將它們用於其他原因不是一個好主意。 – TLP