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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Can CGI.PM do hyperlinks
by derby (Abbot) on Feb 22, 2007 at 21:13 UTC

    yes.

    #!/usr/local/bin/perl use strict; use warnings; use CGI qw/:standard/; print p( "Return to our", a( { -href => 'fred.html' }, "home page" ), "." );

    but I think you'll find a large number of monks that abstain from using the HTML generation portion of CGI in favor of a templating system.

    -derby
Re: Can CGI.PM do hyperlinks
by Joost (Canon) on Feb 22, 2007 at 20:31 UTC
Re: Can CGI.PM do hyperlinks
by davorg (Chancellor) on Feb 23, 2007 at 09:14 UTC

    Are you planning to ask about every individual HTML element that you want to use?

    CGI.pm can generate any HTML element that you want. The rules for doing it are very simple and given in the documentation.

    • If you call a method with the name of an element, then it returns an example of that element.
      $cgi->a; # returns <a />
    • If you pass a string to the method, then that string will be put inside the element.
      $cgi->a('some text'); # returns <a>some text</a>
    • If the first parameter that you pass to the method is a hash reference then that is interpreted as the attributes for your element.
      $cgi->a({href=>'http://somewhere/'}, 'some text'); # returns <a href="http://somewhere/">some text</a>

    That's all you need to know to produce 95% of the HTML tags that you need. The exceptions to these rules are listed in the documentation, but the tags that follow these rules aren't - as that would make the documentation unnecessarily long and repetative.

    So here's a suggestion. The next time you want to produce an HTML tag that you haven't asked us about, then try applying these rules. In 95% of cases it will work. If it doesn't (and you can't find it mentioned as an exception) then post a message here saying something like "I tried to create a foo tag using code like this (...) but it doesn't work as I expected."

    But as you've been told before, your life will be far easier if you use a templating system for this.

Re: Can CGI.PM do hyperlinks
by EvanK (Chaplain) on Feb 22, 2007 at 21:14 UTC
    In addition to the CGI docs, check this node. the issue with the way CGI generates html is that it uses referenced and anonymous data types, which tend to confuse the newbies (i should know, i'd been one for a very long time).

    __________
    Systems development is like banging your head against a wall...
    It's usually very painful, but if you're persistent, you'll get through it.

Re: Can CGI.PM do hyperlinks
by ww (Archbishop) on Feb 22, 2007 at 20:40 UTC

    Have you read the documentation?

    for example: %perldoc cgi or C:\perldoc cgi, as the case may be.

    See, particularly "CREATING STANDARD HTML ELEMENTS:"