in reply to image and href tags in CGI.pm

print a({href => "http://www.web.com"} ,img({src=>'/web.gif'}));

But honestly doesn't that seem like more work than just printing it?

Replies are listed 'Best First'.
Re^2: image and href tags in CGI.pm
by BUU (Prior) on Jan 03, 2005 at 20:45 UTC
    But honestly doesn't that seem like more work than just printing it?
    Yes, it does. And to the original poster, please don't use CGI.pm to generate HTML. It's a horrible, horrible sin against humanity. Not only do you have the usual flaws of embedding the html(presentation) in your code(control), you don't even make the html in an easily recognizable form. It's in some bizarre CGI.pm language which is a pain in the ass to find.

      Hi,

      I politely disagree with your comment about CGI.pm. It is actually quite easy to use with a moderate learning curve. Whether or not to use a template is mostly by design of the project and personal preferences. Each has their uses.

      Jason L. Froebe

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

        Disagreeing is fine, this is perl after all, but my main criticism of CGI.pm's html generating function is not that they are easy to use, it is that they are very ugly. Do you honestly find:
        print table(tr(td(a(-href=>'http://google.com',"http://google.com"))))
        easier to read than
        print "<table><tr><td><a href='http://google.com'>http://google.com</a +></td></tr></table>";
        ?

        As for templates, I've yet to see a situation where *not* using templates is better design. People often refuse to use them, mostly due to false laziness (but occasionally it is a good laziness), but that doesn't make it good design.

      I wonder what's worse. Some guy writing code the way he wants (using CGI.pm) or some (HTML::)Template( Toolkit) zealot...

      Your reaction is nothing but a Pavlovian reaction. Instead of explaining what is wrong with producing CGI.pm HTML in a normal way, you try to make the OP look bad for even talking about CGI.pm. You don't know anything about the project (s)he's working on, so you can't tell wheter using CGI.pm is really a bad choice.

      Just because you think(/read that) using CGI.pm for HTML creation is bad, doesn't mean that others can't be happy with it.

      Please, please give some more structured criticism instead of this zealotry.

      --
      b10m

      All code is usually tested, but rarely trusted.
        Which part of
        Not only do you have the usual flaws of embedding the html(presentation) in your code(control), you don't even make the html in an easily recognizable form.
        Did you not understand? I present two clear criticisms. One is that embedding the html generation in the code is usually a bad idea REGARDLESS OF THE APPLICATION. The second is that the embedded form of the code is extremely ugly when you use CGI.pm. Using CGI.pm to produce html leads to complicated overdone code that is hard to read and understand.

        And yes, templates are good, but I'd much rather see the person just use prints statements to output the html, rather than the horrible functions exported by CGI.pm.

        Update Just a node responding to both replies: Nothing I have said precluded the possibility of keeping the script as one file. Any sane templating system (HTML::Template, just for example) will let you embed the template *in* the same file as your script is, for example below the __DATA__ line, or even just as a giant quoted string.