in reply to RE: Obtain matrix info
in thread Obtain matrix info

Dave,

First of all, let me tell you that I am entirely self-taught. I began to hear about the CGI.pm module only recently! Before that, I tried to learn copying&pastings and then re-writing. This is something that I had seen in another script; and I had been using this since.

The CGI parameters, I believe, are just like variables. A variable name should be unique, so should a CGI parameter. I see no problem in assuming that no parameter name will occur twice. I don't know how CGI.pm module handles this, but it looks like an unnecessary detail.

Replies are listed 'Best First'.
RE: RE: RE: Obtain matrix info
by davorg (Chancellor) on Jul 29, 2000 at 20:33 UTC

    Perl has a real problem in that there are so many badly written CGI scripts around on the web and most people seem to pick up bad habits from them before finding places like perlmonks where they can get good advice. I'd be geniunely interested in hearing any ideas you have about how we can get to new Perl programmers and teach them good habits before they meet Matt Wright and his friends.

    Your assumptions about CGI parameters are wrong. It is perfectly valid to have more than one value for each key. CGI.pm handles this by returning a list of values for multi-valued parameters. the older cgi-lib.pl handles it by returning a string where the values are separated by a \0 character. most hand-rolled solutions (like yours) handle it by trashing all but one of the values.

    I apologise if my original post sounded too much like a flame. All I wanted to do was to point out that there are much better ways to do what you're doing and I hope that having been shown them, you will start to use them.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
      You are right; I saw that piece of code in one of Matt's scripts.

      You don't need to apologise; I am glad that you warned me. At some point, I would need to handle multiple selection boxes...

      In fact, I decided to use CGI.pm some time earlier, and I began with a code I saw at http://stein.cshl.org/WWW/software/CGI/ . But I got some error messages and I inferred that the CGI.pm library was not installed on my server. (I don't have root access.)
      I used
      use CGI qw(:standart)
      .
      May be you can help me out? Did I make a mistake? Thanks for your help!

      Edit kudra, 2001-07-18 Changed title to avoid clash with module

        CGI.pm has been a standard part of Perl for some years now (since 5.004_04 I think). If you have an earlier version than that then you'll need to get it installed (but if you have an earlier version than that on a web server then you have major security holes anyway).

        I'm assuming that it's a typo, but you have mis-spelt 'standard' in your sample above. Is that the problem?

        If you let me know what errors you're getting, then I'd be happy to help you track them down.

        --
        <http://www.dave.org.uk>

        European Perl Conference - Sept 22/24 2000, ICA, London
        <http://www.yapc.org/Europe/>
    A reply falls below the community's threshold of quality. You may see it by logging in.
RE: RE: RE: Obtain matrix info
by merlyn (Sage) on Jul 29, 2000 at 20:23 UTC
    You apparently haven't yet dealt with multiple-select fields then, where you can end up with state=oregon&state=washington&state=california because someone selected all three states from an input field.

    Please don't write CGI handling from scratch. There's a lot to get right, and it really does take something the size of CGI.pm to get all of it right.

    -- Randal L. Schwartz, Perl hacker