tags:

views:

39

answers:

1

I can successfully show image in my CGI scripts via CGI.pm, using this code:

#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
print img {src => "../images/myimage.png", align=>"CENTER"};

However when I want to do is to include URL in that image, wo that whenever people click on that image it will point to the desired url, this code failed:

print img {src => "../images/myimage.png", align=>"CENTER", -href=>"www.google.com"};

What's the right way to do it?

+4  A: 
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
print a( { href => 'http://www.google.com' }, img {src => "../images/myimage.png", align=>"CENTER" } );

# OUTPUT:
<a href="http://www.google.com"&gt;&lt;img align="CENTER" src="../images/myimage.png" /></a>
eumiro