http://qs1969.pair.com?node_id=17805

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

I just have a few basic questions about CGI. say I have a script that is like this:
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "<HTML><HEAD><TITLE>Title Page</TITLE></HEAD>\n"; print "<CENTER><FONT SIZE=+7>Some text here</FONT></CENTER></HTML>\n";
now, I want to use CGI.pm, so I say;
!#/usr/bin/perl use CGI; $q = new CGI; print $q->header; print $q->start_html("Title Page");
now, if all the above is correct, how do I convert the CENTER and FONT tags?

Replies are listed 'Best First'.
(jcwren) Re: CGI.PM related questions.
by jcwren (Prior) on Jun 13, 2000 at 03:08 UTC
    Somthing like this:
    use strict; use CGI; { my $p = new CGI; print $p->header; print $p->start_html ("Title Page"); print $p->p (center ($p->font ({-size=>'+7'}, "This is a test" +))); print $p->end_html; }
    would give you this:
    Content-Type: text/html <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <HTML> <HEAD> <TITLE>Title Page</TITLE> </HEAD> <BODY> <P><CENTER><FONT SIZE="+7">This is a test</FONT></CENTER></P> </BODY> </HTML>
    (I reformatted the HTML to make it more readable. CGI.pm usually runs stuff together)

    It takes a little reading, but 'perldoc CGI' has some pretty good information. There's an excellent tutorial written by Lincoln Stein, that someone has a link to, but I don't know where it is. Anyone?

    --Chris
      jcwren said something like:
      I reformatted the HTML to make it more readable.
      Have you seen CGI::Pretty? Just say use CGI::Pretty blah blah in place of use CGI blah blah. You get newlines and indented output. Cool.

      -- Randal L. Schwartz, Perl hacker

        Per the amazing Randal L. Schwartz, change the lineuse CGI;touse CGI::Pretty qw (:all);and you'll get pretty printing.

        CGI::Pretty is located here, via the CPAN search.

        --Chris
      The recommended test CGI script generates the following error: Status: 302 Found Location: http://cgi2.tripod.com/bin/error?error=Your%20script%20produced%20this%20error%3A%20Unable%20to%20create%20sub%20named%20%22%2AMember%3A%3Acenter%22%20at%20.%2Fhello.pl%20line%2022.%0A URI: http://cgi2.tripod.com/bin/error?error=Your%20script%20produced%20this%20error%3A%20Unable%20to%20create%20sub%20named%20%22%2AMember%3A%3Acenter%22%20at%20.%2Fhello.pl%20line%2022.%0A Content-type: text/html Can anyone tell me what the problem is?
      The recommended test CGI script generates the following error: Status: 302 Found Location: http://cgi2.tripod.com/bin/error?error=Your%20script%20produced%20this%20error%3A%20Unable%20to%20create%20sub%20named%20%22%2AMember%3A%3Acenter%22%20at%20.%2Fhello.pl%20line%2022.%0A URI: http://cgi2.tripod.com/bin/error?error=Your%20script%20produced%20this%20error%3A%20Unable%20to%20create%20sub%20named%20%22%2AMember%3A%3Acenter%22%20at%20.%2Fhello.pl%20line%2022.%0A Content-type: text/html Can anyone tell me what the problem is?