如何理解suball" sub($ c){...}"?

时间:2018-05-22 08:03:28

标签: perl mojolicious-lite

我正在阅读以下的mojo示例: https://mojolicious.org/ 以下是代码:

use Mojolicious::Lite -signatures;

# Render template "index.html.ep" from the DATA section
get '/' => sub ($c) {
  $c->render(template => 'index');
};

......

我的问题是如何获取perl编译的这段代码?通常我会将子代码编码为:

get '/' => sub {
      my $c = shift;
      $c->render(template => 'index');
    };

这可以通过草莓perl很好地编译。虽然来自mojo的示例代码有错误:

D:\Source\test_code\mojotest>perl mojo3.pl daemon
Illegal character in prototype for ? : $c at mojo3.pl line 4.
Illegal character in prototype for ? : $c at mojo3.pl line 9.
Illegal character in prototype for ? : $c, $msg at mojo3.pl line 10.

有人能说出原因吗?

0 个答案:

没有答案