开发者

CGI.pm : include image?

I'm writting Perl/CGI script with the module CGI.pm. I can return text/html, but can't include an image within it, it always display the 'alt' tag and I'm sure about the href link.

Here's my code :

#!/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;


First, you're not getting the alt text. You're sending <img>-src http://www.perl.org/simages/lcamel.gif -alt Powered by Perl, so the image doesn't even have alt text.

The first argument of img should be a hash of attributes. The rest is taken as child elements.

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

The dashes are optional, so you could also use

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜