in reply to Re: image and href tags in CGI.pm
in thread image and href tags in CGI.pm

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.

Replies are listed 'Best First'.
Re: image and href tags in CGI.pm
by b10m (Vicar) on Jan 03, 2005 at 21:04 UTC

    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.
        80% of the CGI interaction out there is "single form, single response" apps. I think your statement doesn't apply there. There's nothing wrong with putting the HTML and the response handler in the same file for that.

        And if you do that, you gain the sticky-fields features of CGI.pm's form creation, and some high level constructs for radio-groups and checkbox-groups.

        I think you're throwing the baby out with the bathwater when you say "don't use CGI.pm's HTML constructs". For 80% of the apps out there, it's just fine. I can agree with you that it doesn't scale, though. And when someone gets to one of those other 20% of the apps, they'll learn Template Toolkit or something.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

        One advantage of using something to generate small amounts of HTML is that as specs change, that single module can be upgraded and your site can meet new specs. Like moving from HTML to XHTML. This is not a general reason for using, and personaly I have never used it. However there are cases (like the generation of some Perlmonks HTML) in which it *can* be a good idea that improves the quality of code. To each his own though, sometimes a print statment just fits the bill, but sometimes it doesn't.


        ___________
        Eric Hodges

        What makes you think that I don't understand what you're posting? I'm merely pointing out that, even when you disagree, you still can be polite, hence my "explaining what is wrong with producing CGI.pm HTML in a normal way"

        I disagree on the way that embedding HTML generation in the code is always wrong. For simple scripts, it can be damned handy to keep everything in one big file. Although I haven't benchmarked it (and I'm not planning to do so), I believe for some scripts it's way faster not to use templates.

        Besides that, your second point is of course totally ridiculous. So because you think the "embedded form of the code is extremely ugly", the OP shouldn't even think about using it?

        So, yeah, to conclude, I have to give you credit for the "two clear criticisms". Those are totally non-biased arguments. Totally not based on opinion and zealotry. Sorry for that. I stand corrected. It's all very clear to me now.

        --
        b10m

        All code is usually tested, but rarely trusted.
Re^3: image and href tags in CGI.pm
by jfroebe (Parson) on Jan 03, 2005 at 21:50 UTC

    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.