the standard also says if I set :html2, xhtml will go away (but it doesn't seem to have an effect)

Not sure which "standard" you're talking about there.

The ':html2' import tag just defines the set of functions that are imported into your symbol table. As you're using the Object interface to CGI.pm it has no effect at all on your program.

my $query = CGI->new; print $query->start_html(-title=>'Argh!', -background=>"../images/$SiteName.background.jpg", -link=>'brown', -vlink=>'#8b4513', -no_xhtml=>1, #this has no effect... -dtd=>'3.2 DTD' # this does the trick, but not listed in # the standard as to how to set it -- I # hope this is right... }

Ah, you seem to be using "standard" to mean "the CGI.pm documentation", which is slightly unusual :-)

The docs say:

If start_html()'s -dtd parameter specifies an HTML 2.0 or 3.2 DTD, XHTML will automatically be disabled without needing to use this pragma.

I think that means that you can override the whole DTD with this parameter. You can't just give it a string like "3.2 DTD", you need to give it a complete valid HTML DTD.

Also, you're using the -no_xhtml pragma wrong (which is why it has no effect). It's not a parameter to start_html() (and nowhere does the documentation imply that). It's in the list of pragmas - which are arguments you give in the "use CGI" statement.

I think that what you want is something like this:

use CGI '-no_xhtml'; my $c = CGI->new; print $c->start_html;

Which produces:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-US"><head><title>Untitled Document</title> </head> <body>

And if I can just make one further comment. Embedding HTML markup in your code using the CGI.pm methods is a really nasty way to go about it. Your life will be much easier if you separate your HTML from your code using some kind of templating system (I recommend the Template Toolkit, but other options are available).

Update: s/usual/unusual/ - thanks to Corion for pointing it out.


In reply to Re^3: XML tags using perl CGI by davorg
in thread XML tags using perl CGI by pmcaveman

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.