How to run an anonymous function in Perl?

前端 未结 7 2011
长发绾君心
长发绾君心 2021-01-31 08:57
(sub {
print 1;
})();



sub {
print 1;
}();

I tried various ways, all are wrong...

相关标签:
7条回答
  • 2021-01-31 09:46

    I'm endlessly amused by finding ways to call anonymous functions:

    $foo = sub {say 1};
    
    sub bar {goto $foo};
    bar;
    
    ''->$foo; # technically a method, along with the lovely:
    
    undef->$foo;
    
    () = sort $foo 1,1; # if you have only two arguments
    

    and, of course, the obvious:

    &$foo();
    $foo->();
    
    0 讨论(0)
提交回复
热议问题