When using CGI.pm, you may also replace:

#!/usr/bin/perl
print "Content-type: text/html\n\n";

With:

#!/usr/bin/perl -w

use strict;
use CGI qw(-no_debug :standard);
my $q = new CGI;

print $q->header; # prints default 
                  # content-type, 
                  # which is text/html

# rest of progam...

__END__

 Notes: qw(-no_debug :standard) is
 for disabling command line input
 and only importing the standard 
 functions in CGI.pm, instead of
 ALL of them -- which you probably
 don't need.

 $q is the same as $query in your 
 example. You can name that variable
 anything you wish. 

 $q is your new CGI object, -> means 
 your actually pointing to a function
 in CGI.pm. the text after the -> is
 the function you would like to use.

 i.e. $q->header;

      This is your new CGI object ($q),
      referencing the header() 
      function in the 'standard' set
      of functions that you imported 
      from CGI.pm.

 Finally, test your program, as you go,
 from the command line like so, to test 
 for errors:

 /path/to/perl -wc <program_name>

 (where <program_name> is the name of
 your script.)

 Cheers!


In reply to RE: Re: I almost got it! by Anonymous Monk
in thread I almost got it! by MAS4891

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.