CGI.pm:包括图片?

eou*_*uti 1 perl cgi

我正在使用CGI.pm模块编写Perl/CGI脚本.我可以返回text/html,但不能在其中包含图像,它总是显示'alt'标签,我确定href链接.

这是我的代码:

#!/usr/bin/perl -w
use strict;
use CGI;

my $cgi = new CGI;

print $cgi->header(-type=>'text/html'),
      $cgi->start_html(-title=>'Test Page'),
      $cgi->h1('Infos switch'),
        "This is a test.",
      $cgi->h1('Testing'), $cgi->hr, "\n",
      $cgi->img(-src=>'http://www.perl.org/simages/lcamel.gif',  
                -alt=>'Powered by Perl'), "\n\n",
      $cgi->end_html;
exit;
Run Code Online (Sandbox Code Playgroud)

ike*_*ami 5

首先,你没有得到替代文字.您正在发送,因此图片甚至没有替代文字.<img>-src http://www.perl.org/simages/lcamel.gif -alt Powered by Perl

img的第一个参数应该是属性的哈希.其余部分被视为子元素.

$cgi->img({
   -src => 'http://www.perl.org/simages/lcamel.gif',  
   -alt => 'Powered by Perl',
})
Run Code Online (Sandbox Code Playgroud)

破折号是可选的,因此您也可以使用

$cgi->img({
   src => 'http://www.perl.org/simages/lcamel.gif',  
   alt => 'Powered by Perl',
})
Run Code Online (Sandbox Code Playgroud)