student has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone tell me how to put a hyperlink into a cgi script? I need to make a hyperlink to "Return to Selection page" ...which is my home page. I am having a hard time finding the answer. Thanks.

Replies are listed 'Best First'.
Re: Hyperlinks within .cgi scripts
by fraterm (Scribe) on Nov 20, 2004 at 04:38 UTC

    What you most likely need to do is add an

    <a href="http://server/selectionpage.html">Anchor</a>
    to the output of the script... which is viewable in a browser right?

    Check the CGI.pm authors website use your magical find feature to find the term "anchor link", or the perldoc in question for the methods for making the tag... though if you just print "<a>whatsit</a>"; it might just work... you'll most likely need to escape stuff though that might confuse perl while it parses your poo.

    Arrr, alas I be, Initiat-eee-d.
Re: Hyperlinks within .cgi scripts
by rev_1318 (Chaplain) on Nov 20, 2004 at 19:58 UTC
    if you use CGI.pm:
    print a({href => "/index.html"}, "Return to Selection page")
    See perldoc CGI (section 'CREATING STANDARD HTML ELEMENTS:') for more on this.

    Paul

Re: Hyperlinks within .cgi scripts
by WebDragon (Initiate) on Nov 21, 2004 at 07:08 UTC

    I tend to prefer the function-oriented interface of CGI.pm, even with the extra overhead, but YMMV.

    use CGI qw/:standard/;

    Note that it's fairly easy to both concatenate with commas, and to nest, so that it looks very close to actual html. :-)

    print p({-class=>"highlight"}, "If you need to return to the selection page, you can ", a({-href=>"/index.htm", -class=>"backlink"}, "click here"), "to go back." );