Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

CGI.pm HTML vs. W3C HTML Validation

by jlongino (Parson)
on Dec 29, 2001 at 02:08 UTC ( [id://134997]=perlquestion: print w/replies, xml ) Need Help??

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

I've never used CGI.pm to produce HTML before and decided that it was high time I did so. My primary uses for Perl are sysadmin tasks and data munging and I've written only a few web applications.

In all of my programming endeavors I try to develop a cache of basic "templates" from which to build upon. My question is does anyone have an example of a Perl script that uses CGI to create a simple HTML document (e.g., displays a simple table) which passes W3C HTML Validation?

I have done a little research (though perhaps not as much as I could have) e.g., I perused some of the CGI tutorials/courses by Ovid and cut/pasted a couple of sample programs but I get errors followed by the message:

Sorry, this document does not validate as HTML 2.0
Note that I'm not criticizing Ovid, I deeply appreciate the fact that he's gone to so much trouble and have picked up some extremely useful concepts that will come in handy for later projects. I'm also fairly sure that it was not his intent that the examples I used be W3C compliant. I also composed a simple page using the NS composer which didn't pass either.

Is trying to conform to W3C standard desirable or overkill? Although my first attempts will be extremely simple, I don't want to start out by acquiring bad habits. Especially when I have a resource like the monastery at my disposal. TIA for any help.

--Jim

Replies are listed 'Best First'.
(Ovid) Re: CGI.pm HTML vs. W3C HTML Validation
by Ovid (Cardinal) on Dec 29, 2001 at 02:26 UTC

    If you're using the latest versions of CGI, they produce valid XHTML. I seriously doubt those will validate as HTML 2.0 (IIRC, we're on HTML 4.1 now). In fact, the programmer has very little control over the HTML that CGI generates. Actually, if you really want to get into it, the Web pages themselves render properly, but aren't valid. I worked like mad trying to put that thing together and now have so many other projects going on that I can't seem to get back to it.

    I tried running the pages through HTML Tidy at one point, but that seriously broke all of the CSS. Since I've not found any browsers that the pages break, I elected to move on to more pressing matters. If you don't want XHTML, you can check to see if the pages validate with the following use statement:

    use CGI qw/-no_xhtml/;

    And to answer your question about the wisdom of conforming to W3C standards: this is a Good Thing. If people keep ignoring standards, the Web will be an even worse place than it already is. Heck, the latest IE security hole (having executables silently download and run just by visiting the Web site) is a direct result of MS ignoring the standards -- probably with the intent of having other browsers break on MS only Web sites.

    Further, if your HTML validates as W3C compliant, this doesn't guarantee that it will render exactly as you expect, but it's one heck of a lot more likely to do so.

    Hope that helps! (and thanks for the plug :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: CGI.pm HTML vs. W3C HTML Validation
by gav^ (Curate) on Dec 29, 2001 at 02:30 UTC
    I tend to run a lot of my stuff through HTML-Tidy which is great for fixing/cleaning up HTML code.

    You'll find that most non-compliance warnings can be ignored, most browsers don't comply with the W3C standard anyway. Now that style sheets are (more or less) standard, though several versions of Netscape are rather broke, I rely on this and use as simple html as possible.

    Regarding CGI.pm to generate your HTML, I really wouldn't bother, I hate having the HTML in my scripts, it makes maintance a pain and it stops a non-programmer being able to easily change things. Personally I like using HTML::Template as it seems to work well. I find the designers I work with can deal with it without any problems.

(ichimunki) Re: CGI.pm HTML vs. W3C HTML Validation
by ichimunki (Priest) on Dec 29, 2001 at 02:13 UTC
    HTML 2.0?? WTF? That's about eight years old now. I'm guessing that there are many newer tags and attributes that did not exist in 2.0. CGI.pm produces conformant XHTML, if not doing so, that's a bug report to write.
      BTW, I am making no assumptions as to what the problem is. I had noticed a few posts mention web pages that were not W3C compliant and figured that W3C was a useful resource.

      On the other hand I've had my share of Doh! posts, so I certainly wouldn't rule out pilot error. One URI I tested was this if that helps any.

      --Jim

        The doctype in that page is not what I would expect to see from a typical CGI.pm output, it lacks the usual version numbering and "strict", "transitional", etc information. That is causing the validator to assume the worst about the page. And I don't see anything on that page that wouldn't validate other than the header itself, unless BGCOLOR wasn't a valid attribute in 2.0.

        FWIW, I just submitted one of my own CGI.pm-made HTML docs and found that it does not validate, but because the header says the doctype is XHTML basic, and the header itself uses the lang attribute, which is not in basic apparently. So your point is perhaps valid, but this may even be fixed in newer versions of CGI (I'm on whatever ActiveState included with ActivePerl).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-24 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found