想象一下這樣的子程序:如何正確調用帶2個子程序引用的子程序?
sub test(&&)
{
my $cr1 = shift;
my $cr2 = shift;
$cr1->();
$cr2->();
}
我知道我可以把它想:test(\&sub1,\&sub2)
,但我怎麼能這樣調用它:
test { print 1 },{ print 2 };
如果我說的子程序只需要一個&
,比發送一個塊將工作。我不知道如何使它與2
工作,如果我嘗試這樣運行它,我得到:
Not enough arguments for main::test at script.pl line 38, near "},"
編輯:有沒有調用沒有sub
的方式嗎?
爲什麼? (你想避免使用'sub'關鍵字) – Ether 2009-10-25 18:18:30
我希望它看起來更'DSL'-ish。 – Geo 2009-10-25 18:25:44
祝你好運與源過濾器,我猜:) – bdonlan 2009-10-25 18:27:59