Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: I use CGI.pm for

by royalanjr (Chaplain)
on Jun 08, 2000 at 00:05 UTC ( [id://16941]=note: print w/replies, xml ) Need Help??


in reply to I use CGI.pm for


Call me crazy, but I generally do not let CGI.pm do my HTML. I prefer to write that out myself. Being new, I know I have not explored all its possibilies yet though. I do use it to pass my parameters around.

Roy Alan

"I quit; I concede. Tanj on your silly game!" -- Louis Wu

Replies are listed 'Best First'.
RE: RE: I use CGI.pm for
by BBQ (Curate) on Jun 08, 2000 at 01:16 UTC
    Ok, you're crazy. :)

    I guess I'm worse cause I still use the "cgi-lib.pl compatility mode" with ReadParse(*in); Now is that lame or what?

    #!/home/bbq/bin/perl
    # Trust no1!
RE: RE: I use CGI.pm for
by merlyn (Sage) on Jun 08, 2000 at 04:51 UTC
    Thus saith royalanjr:
    Call me crazy, but I generally do not let CGI.pm do my HTML. I prefer to write that out myself. Being new, I know I have not explored all its possibilies yet though. I do use it to pass my parameters around.
    Once you discover the sticky fields technology of web form generation, you'll never go back. CGI.pm rules!

    -- Randal L. Schwartz, Perl hacker

      Not to mention, with some creative map use, you can create dynamic tables and such pretty easy, while not breaking the stylish print 'some','things','in','a','row'; :-)
      use CGI;
      my $cgi = CGI->new;
      print $cgi->header,
            $cgi->start_html('Times Tables'),
            $cgi->table( { -border => 1 },
                       ( map {
                        my $r = $_;
                        $cgi->Tr( ( map {
                                 $cgi->td( $_ * $r ),
                                } 1 .. 50 ) ),
                       } 1..50 ) ),
            $cgi->end_html;
      
      And for the obfuscated lovers in all of us (some people would call the above obfuscated.. slackers:-)
      use CGI;my$cgi=CGI->new;print##
      $cgi->header=>$cgi->start_html#
      ('Times Tables')=>$cgi->table(#
      {-border=>1}=>(map{my$r=$_;$cgi
      ->Tr((map{$cgi->td($_*$r)}1..50
      ))=>}1..50))=>$cgi->end_html;##
      
      --
      Casey
      
      I've run into a case where CGI.pm was a little too sticky. Still, it's really a good way to go, as you don't have to worry about updating code in a script somewhere when the HTML specification changes.

      Has anyone tried the 3.0 alpha versions? They're supposed to be much smaller and much, much faster.

        I agree. Sometimes the stickiness make a script to behave strange, especially if you have a muliple page form generation / evaluation script with hidden fields.
        There is a good idea to try the 'override' flag on hidden fields if such a script behaves strange.

        /Wonko

      Sticky Fields?!?

      *pulling at my hair in despair, dropping to my knees*

      So much to learn!!!

      Roy Alan

      "I quit; I concede. Tanj on your silly game!" -- Louis Wu

        Sticky fields is a CGI.pm facility which is useful when you have a CGI script which returns multiple forms; The script automatically fills in the old formfield data (i.e. the data that has already been posted)
        This is wery useful if you want to keep track of the information the user has already entered in hidden fields, or if you have to resend a form because the user did something wrong
        /wonko
RE: RE: I use CGI.pm for
by flyfishin (Monk) on Jun 08, 2000 at 00:49 UTC
    Try it you'll like it. I certainly do. It takes a little bit to get used to but the shortcuts for creating multiple table rows and table data are invaluable. I certainly don't know all it can do but the little that I do know sure seems to go a long ways. It is also easy to switch from using CGI.pm notation for HTML to simple here documents, if I want to write out HTML by hand.
      Personally, I use a mix of it, pending on what i shall do and who i am writing it for. Sometimes I find it easier to use the HTML tags rather than the shortcuts, especially when i make complicated tables.
      And there's always the option of a external HTML file and use regexps to insert variables:
      open(HTML, "<a_file.html") or die "cant open HTML file: $!\n"; while($row = <HTML>) { $row =~ s/---(.*?)---/eval $1/eg; print $row; } close HTML;
      Which will look for ---$variablename--- in the HTML code and replace it with the variable (as if you didnt know ; )) I also use HTML comment flags to insert more complicated structures. I've written a rather simple Web-based discussion forum using this technique, which allows the administrator of the site to change the design without knowing any Perl at all.
        At one place I worked, we found the template idea to be the most flexible way of doing it -- namely because then we could use the same subs for filling out not only HTML but reports written in LaTeX, E-Mail reports, etc.

        I myself started out using CGI.pm, then as time went on used less and less of it until I finally just kicked in a sub to parse the parameters and left out the module completely. I guess I'm just obsessive about my HTML :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://16941]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-18 01:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found