跟着摩乔斯特,第二集学习动感。
我有个例子
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/:fname/:lname' => sub {
shift->render('hello');
};
app->start;
__DATA__
@@ hello.html.ep
<!doctype html><html>
<head><title>Placeholders</title></head>
<body><i>Hello <%= fname %> <%= $lname %></li></body>
</html>但是,当我转到address http://127.0.0.1:3000/sayth/renshaw时,我从服务器上得到了这个错误。
[Fri Apr 25 15:59:05 2014] [error] Bareword "fname" not allowed while "strict subs" in use at template hello.html.ep from DATA section line 3, <DATA> line 17.
1: <!doctype html><html>
2: <head><title>Placeholders</title></head>
3: <body><i>Hello <%= fname %> <%= $lname %></li></body>
4: </html>我不相信我已经指定了严格的潜艇,我该如何解决这个问题?
编辑:我正在运行由curl安装的最新版本,安装了perl 5.16.3。
发布于 2014-04-25 06:26:42
默认情况下,Mojolicious启用了use strict;。感恩:)
错误与您在perl代码中得到的相同:
Bareword "fname" not allowed while "strict subs" in use at template hello.html.ep基本上,你只是在fname之前少了一个美元符号
@@ hello.html.ep
<!doctype html><html>
<head><title>Placeholders</title></head>
<body><i>Hello <%= $fname %> <%= $lname %></li></body>
</html>或者您也可以使用这种格式:
@@ hello.html.ep
<!doctype html><html>
<head><title>Placeholders</title></head>
<body><i>Hello <%= param('fname') %> <%= param('lname') %></li></body>
</html>https://stackoverflow.com/questions/23285305
复制相似问题