in reply to Re: Code Critique?
in thread Code Critique?

Why do you say that one should avoid mixing CGI.pm's HTML functions with here documents?

I often do something similar to the following:

use strict; use CGI; #tested on 5.005/UNIX my $q = new CGI; print $q->header(), $q->start_html(-title=>'CDB Form'); print <<END_of_Multiline_Text; HTML text here END_of_Multiline_Text print $q->end_html();
This enables me to reuse existing HTML code, and I do not have to remember the correct http headers to post. Moreover, I can even interpolate Perl variables in my here document if I want to.

Replies are listed 'Best First'.
Re: Re: Re: Code Critique?
by Masem (Monsignor) on Jun 15, 2001 at 21:33 UTC
    Well, it's not that this doesn't work. As with most of perl, TIMTOWTDI. But I was more advocating mixing here-docs with CGI's functions, (as opposed to mixing CGI.pm with here-docs)

    I've lately becoming less enthralled with here-docs due to how they ususally mess up the formating (both of what you put in and what your editor puts in) of a perl script. Plus, this appears to be one of the few points in perl where extra whitespace can screw you up. I've had several bad experiences with here-docs as to avoid using them myself and to try to get others to do so as well.

    It's probably better to use either CGI.pm functions completely, or at least get the header and other page information out with CGI and then jump to a template solution for the rest of the HTML body. Both methods will produce much nicer and easier-to-read code than using here-docs.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      We are basically on the same (web) page. A lot of us have legacy HTML pages that we are integrating into new projects, and it is better to reuse them than to redo them as templates or using CGI.pm's HTML functions.

      I prefer to include the legacy HTML pages as here documents rather than as separate files. That way everything is one one file. In my office we are still working the kinks out of our version control system and anything that avoids adding to the number of files in a project is a plus.