Rich Fernandez wrote:
: I'm playing around with a web page that serves up an image or video file.
: If I use straight HTML I can create a link that says something like "<img
: src=myfile.mpg>" and have the video display when the link is clicked, but I
: can't get the right syntax using CGI.pm. Probably trivial, but...
: 
: The link that I'm testing with looks like this: "<a
: href=http://gromit/cgi-bin/juggling.pl?video=rr.mpg>Rubinstein's
: Revenge</a>"
: 
: Here's my code...
: 
: -----------------------------------------------------------
: #!/usr/bin/perl -w
: use strict;
: use CGI;
: 
: my $query = CGI -> new();
: my $vidfile = $query -> param("video");
: print $query -> header();
: 
: <the mystery statement>

The mystery statement is

print STDOUT 
$query->a({href=>"http://gromit/cgi-bin/juggling.pl?video=rr.mpg"},"Rubinstein's 
Revenge");

You could also do a stright print:

print STDOUT "<a href=http://gromit/cgi-bin/juggling.pl?video=rr.mpg>Rubinstein's 
Revenge</a>";

In a CGI script, anything you print to STDOUT will go to the browser.
All the a() method from CGI.pm does- or any of CGI,pm's HTML shortcuts,
for that matter- is return the string to be printed. There's nothing
magical about the shortcuts; they just produce HTML tags that you could
produce by hand.

<editorial>
In fact, I prefer not to use CGI.pm shortcuts except to draw form
elements, like textfields & checkboxes & such. For them, it's great
because it keeps the values "sticky" between calls to the same script.
However, my scripts draw pages with large tables in them, containing
~1000 rows with ~20 columns/row, and I've found that replacing
shortcuts like Tr() and td() with strings gave me much better
performance.
</editorial>

-- tdk

Reply via email to