in reply to CGI problem: trying to assign parameters in a loop

I'll just make the comment that embedding HTML in perl scripts is BAD.

Seriously with templating solutions such as HTML::Template and Template-Toolkit there is no need to do it.

Update: tutorial for TT here and a comparison of various templating systems here.

gav^

  • Comment on Re: CGI problem: trying to assign parameters in a loop

Replies are listed 'Best First'.
Re: Re: CGI problem: trying to assign parameters in a loop
by Juerd (Abbot) on Jan 19, 2002 at 23:27 UTC
    Sigh.

    Yes, templating is a nice solution to a number of problems, and can really clarify your code. But keep in mind it is not always bad. Sometimes a quick-and-dirty solution is easier. Many people like Perl because it enables you to do things that would otherwise take hours to do.

    • Object orientation is always better
      In many cases, OO is just a pain in the ass, and a functional interface is better. I really like perl 6's ability to create your own operators.
    • Embedding text in scripts is always wrong
      A quick-and-dirty solution can save both time and money. Besides, there's nothing wrong with embedding just a little. In situations where overloaded servers have to be used, templating can be too slow.
    • Prototypes should never be used
      Tilly told me why prototypes are bad. And they sure are. But sometimes, they're good. The (&@) for creating map-like syntax, or the () prototype to let perl inline your sub (great for constants).
    • Calling external programs when perl can do it is about as wrong as it can get
      There's the quick-and-dirty approach again. Although wrong in many production projects, it can speed up development a lot if you're creating a one-time hack, or a simple sysadmin script.
    • XML is the #1 way to store data
      XML is a hype. XML is a nice format to store data in, but there's a lot of ways to do it. I personally dislike pipeline seperated files, but even those can be quite good.
    • Never use a regex to grab the filename out of a path
      ($foo = $bar) =~ s!.*/!! is easier than using File::BaseName. The code's not portable, but not all code has to be.
    • Death to Dot Star!
      Dot star has a function. If you know what it does, and it does what you want, USE IT.
    • Etcetera etcetera
      Many things, including templating are overrated. Some developers (including yours truly) forget there are other solutions that can be as good, or maybe even better in particular cases.
    Maybe you're right about this script. Maybe _this_script_ should use a templating solution. Add "in most cases", "in this case" or something like that and you're right.

    Keep in mind: TIMTOWTDI, and some ways TDI are better than others, but that doesn't mean the worse ways should be avoided completely.

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      If it is not a throw away script then you need to attempt at least some good programming practices.

      In my experiance I've found that too many simple hacked together CGI scripts stay in production because a) they work and b) nobody has the time/money to fix them. The problem is that 6 months down the line somebody normally has to make a small change, which turns out to be another hack and so on and so forth.

      Sometime you have to sit down and say, lets make this work properly and do it in a way that allows simple maintanance.

      I have a big problem with embedded HTML in CGI scripts, I might be the one that has to maintain it and then I've got to spend ages trying to work out how it works.

      Plus in his code he used the normal perl quoting which means he has to remember to put a \ in front of each quote which is a royal pain in the arse.

      What's wrong with:

      use File::Basename; $foo = basename($bar);
      It's a hell of a lot more obvious what this does than your rexexp.

      gav^