这是代码:
如果我像这样调用它:
这是代码:
sub function($&) {
my $param1 = shift;
my $code = shift;
# do something with $param1 and $code
}
如果我像这样调用它:
function("whatever") {
print "i'm inside the coderef\n";
}
我收到了x.pl
文件中第5行的错误提示:Not enough arguments for MyPackage::function at x.pl line 5, near ""whatever" { "
。我想知道如何调用它而不必在代码块前添加sub
?
function("whatever", sub { print "I'm inside the coderef\n" });
只有当coderef在第一位时才能使用name BLOCK EXPR
语法。 - friedo