perl子程序输出附加" 1"

时间:2016-09-22 13:37:12

标签: html perl templates

我正在玩子程序。它完全正常工作,但现在当我调用sub admin_view时,我在页面底部得到一个随机返回值: 1

Home.pl

#!/usr/bin/env -w perl
no warnings 'experimental::smartmatch';

use Cwd qw(abs_path);
use feature qw(switch);
use CGI::Simple;
use HTML::Template;

my $cgi = CGI::Simple->new;
my $action = $cgi->url_param('cmd') || ''; #Set to: URL/?cmd=
my $mode = $ARGV[0]; #accept entry from terminal
print $cgi->header; #make html appear

if($action eq "") {
    #if URL/?cmd=
    $mode = "home";
}

if($action eq "admin_view") {
    #if URL/?cmd=admin_view
    $mode = admin_view;
}

given($mode){

when(admin_view) {
#html: Admin Mode & Display posts
    use rawr::template qw(admin_view);
    print &admin_view;
}

when(home) {
    print "Some home page";
}

##Default message
  default { print "mode not implemented" }
}

Template.pm

package rawr::template;
#template stuff

use strict;
use warnings;
use Exporter qw(import);
use HTML::Template;

our @EXPORT_OK = qw(admin_view);

sub admin_view {
# open the html template
##Yuck hardcoded but ok, works for now. some reason ../tmpl/admin_view.tmpl doesn't work
my $template = HTML::Template->new(filename => '/srv/mydomain/www/rawr/tmpl/admin_view.tmpl');
# fill some parameters
   $template->param(ALIAS => "Some User");
   $template->param(CONTENT => "Hardcoded Content");
   $template->param(DATE => "Date - change me");
   $template->param(TITLE => "Hardcoded - change me");

# send Content-Type and print the template output
   print "Content-Type: text/html\n\n", $template->output;
}
1;

admin_view.tmpl

    <table border="1" id="container">
            <tr>
                    <td id="main_content">
                    <ul>
                    <li onclick="showmenu(this)">!<b>PROFILE</b>
                    <ul>
                            <li><a href="#">Modify</a></li>
                            <li> Delete</li>
                            <li> Lock</li>
                            <br>
                    </ul>
                    </li>
                    <br>
                            <TMPL_VAR NAME=ALIAS>
                    <br>
                    <br>
                            <TMPL_VAR NAME=DSP>
                    <br>
                </td>


<td id="main_content" class="opacity_box" >
<b><TMPL_VAR NAME=TITLE></b> <TMPL_VAR NAME=DATE>
            <br>
            <br>
                             <TMPL_VAR NAME=CONTENT>
            <br>
</td>
</tr>
</table>

模板输出正常,但在页面底部,我在最后</table>标记后得到 1 的随机输出

</table>1

该问题的任何解决方案?欢呼声

1 个答案:

答案 0 :(得分:6)

您的&#39; admin_view&#39; sub做印刷品。

因此,您不需要像这样调用

print &admin_view;

因为这样做,它会打印子的返回码。哪个是没有显式返回的最后一个命令的结果,因此向我们显示print成功。

尝试

admin_view;

(失去&糟糕的风格)

相关问题