http://www.perlmonks.org?node_id=14430

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

I'm trying to do some tables in perl, and by reading various examples I see objects/functions like "td", "Tr", "caption", etc. Looking through CGI.pm, both in the pod and the source, I don't see many references to any of these things that would give me greater insight into how they work, how they can be nested and/or assembled, etc. Short of buying Yet Another Perl Book, where can I get the best reference material on all the functions or objects inside CGI.pm? If I need to buy a book, which would you recommend? I already have the ORA "Learning Perl" and "Perl Black Book" by Holzner. Neither seems to have what I'm looking for.

Replies are listed 'Best First'.
Re: Where can I find a complete reference for CGI.pm?
by KM (Priest) on May 23, 2000 at 23:51 UTC
    The CGI.pm documentation is pretty good, and shows some examples that should really show you everything you want to do. You could also look at the source to see what is going on. Lincoln also wrote a book, "Official Guide to Programming With Cgi.pm", ISBN 0471247448. It was done in 1998, so some things have been added to the module since then. But, except for the POD, what are you not understanding?

    Cheers,
    KM

      Well there's an example of a Table object in the POD in CGI.pm, and it uses caption, td, Tr, etc. Are those all the other objects that can be used in a Table object? If not, what are the others? What "arguments" can td, Tr, etc, all take? Nowhere in the source for CGI.pm are references made to these "subobjects" to where I can see how they function, or what their scope is, etc. Unless I'm just missing it. I'm using 5.005, btw. Maybe 5.6 does a better job, I don't know. Updating to 5.6 is on my (long) list of things to do...
        When you are making a table, what do you use except for TD and TR? These methods (they are not objects) can take whatever params you want to give them, like:

        print td({-align=>'CENTER', -colspan=>2}, $data);

        Read the POD again, and experiment. You can nest the methods to create the HTML you want. If you want to see how they function, read the source code. I don't know what you are referring to for 'scope', since they are methods you import (or access via a CGI object).

        Cheers,
        KM

        Any named parameter not explicitly supported by CGI.pm's methods will be passed along as-is into the tag:
        chh@scallop chh> perl '-MCGI qw(:standard)' -le 'print td({-BOB => "fo +o", -CAT => "bar"}, "lala")' <TD BOB="foo" CAT="bar">lala</TD> chh@scallop chh>
        And you can always write the HTML yourself. I don't particularly like CGI.pm's HTML-generating methods.
        This is a bit of a repeat of KM's post but Tr and td are simply the table row and table data tags of HTML. Whatever options you can put in a table row tag or a table data tag you can put in Tr and/or td. As KM mentioned it will take whatever arguments you pass it. The beauty is that if a new attribute is added to one of those tags you simply add that attribute in the arguments list of Tr or td.
RE: Where can I find a complete reference for CGI.pm?
by merlyn (Sage) on May 24, 2000 at 00:08 UTC
      Not a trick ... just a case of my feeling there was more to it than I was seeing in the documentation. Everyone is telling me that the documentation IS in fact complete ... I guess I was missing the point that all the methods/arguments to the Table command are really just all the tags that you would use inside an HTML table block anyways, and nothing "inherent" in the Table method as defined in CGI.pm
Re: Where can I find a complete reference for CGI.pm?
by husker (Chaplain) on May 24, 2000 at 01:20 UTC
    OK all ... I'm getting the impression I was making this harder than it really was. I was just thinking "is this all there is?" and the answer is "yes". Thanks for your assistance, as always!
Re: Where can I find a complete reference for CGI.pm?
by athomason (Curate) on May 24, 2000 at 02:24 UTC
    I think husker was looking for a doc that resembled a reference more than a tutorial like the CGI.pm POD. That is, something along the lines of an alphabetical list of all the functions with a list of the named parameters that each function explicitly handles. However, since so much of using CGI.pm is in the art of nesting functions and using HTML tags that are parsed untouched into the HTML, this doesn't really get you too far. AFAIK, such a document doesn't exist anyhow. You're best bet is just to read the POD through and through and have an HTML reference handy.
RE: Where can I find a complete reference for CGI.pm?
by Anonymous Monk on May 24, 2000 at 02:56 UTC
    Official Guide to Programming with CGI.pm by Lincoln Stein. Available from amazon.com or bn.com. ISBN 0-471-24744-8
Re: Where can I find a complete reference for CGI.pm?
by princepawn (Parson) on May 24, 2000 at 00:32 UTC
    Well, I strongly recommend Lincoln Stein's website: http://stein.cshl.org And of course I recommend his book from Addison-Wesley