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

Hi,

I set this to meditations, because I don't believe there is an answer to this problem. OTOH if I really do what I started to think "just accept the behaviour", then I open up a door where madness lies behind.

Given this simple code:

print <<"HTML"; <TABLE border=0 cellpadding=0 cellspacing=0 align=center> <TR> <TD height=100%>&nbsp;<BR></TD> </TR> <TR> <TD align=center class=copyleft valign=bottom> (c) 2003 Blah, $cust{'last change'}: $cfg{lastchange}, $cust{feedba +ck}: <A href="mailto:$cfg{webmaster_email}">$cfg{webmaster_email}</A><BR +> <A href=terms.cgi>$cust{terms2}</A><BR><BR> </TD> </TR> </TABLE> HTML print <<"HTML"; </BODY> </HTML> HTML

Voila! It works.

Doing a simple change during refactoring:

print <<"HTML"; <TABLE border=0 cellpadding=0 cellspacing=0 align=center> <TR> <TD height=100%>&nbsp;<BR></TD> </TR> <TR> <TD align=center class=copyleft valign=bottom> (c) 2003 Blah, $cust{'last change'}: $cfg{lastchange}, $cust{feedba +ck}: <A href="mailto:$cfg{webmaster_email}">$cfg{webmaster_email}</A><BR +> <A href=terms.cgi>$cust{terms2}</A><BR><BR> </TD> </TR> </TABLE> </BODY> </HTML> HTML

E voila! It works not. The page sent to the browser and the browser displays all ok, but the apache 2 (mod_perl) also attaches an error message with the wildest codes like 481, 539 etc. and states that either the server is overloaded or there is an error in the CGI script.

You see me puzzled.

Bye
 PetaMem
    All Perl:   MT, NLP, NLU

Replies are listed 'Best First'.
Re: I need a title - sucka! :-)
by jeffa (Bishop) on Nov 21, 2003 at 20:41 UTC
    What happens when you use a real templating engine? No offense, but i stopped using HERE DOCS moons ago, you should too. You should also start writing XML compliant HTML (XHTML). Here is some code to get started. I ran your HTML through HTML Tidy and brought Template along for the ride since you have "class" like entities (cust and cfg). Hope this helps. :)
    use strict; use warnings; use Template; my $tt = Template->new; $tt->process( \*DATA, { title => 'test title', cust => { last_change => scalar localtime, feedback => 'i want my money back!', terms2 => 'sign your name here', }, cfg => { lastchange => "It's never last changed, it's last modified!", webmaster_email => 'admin@nimda.com', }, } ) || die $tt->error(); __DATA__ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content="HTML Tidy, see www.w3.org" /> <title>[% title %]</title> </head> <body> <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td height="100%">&nbsp;<br /></td> </tr> <tr> <td align="center" class="copyleft" valign="bottom"> (c) 2003 Blah, [% cust.last_change %]: [% cfg.lastchange %], [% +cust.feedback %]: <a href="mailto:[% cfg.webmaster_email %]">[% cfg.webmaster_emai +l %]</a><br /> <a href="terms.cgi">[% cust.terms2 %]</a><br /> </td> </tr> </table> </body> </html>

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      No offense, but i stopped using HERE DOCS moons ago, you should too.

      Hi jeffa,

      What have you got against here docs? Or is this just something against here docs to generate (X)HTML?

      --
      Allolex

      Perl and Linguistics
      http://www.wall.org/~larry/keynote/keynote.html

        HERE DOCS were very wonderful before i started using HTML::Template, Text::Template, and the uber Template. Since then, i discovered that HERE DOCS tended to clutter my code, besides ... being able to seperate out other languages from your Perl scripts is good. eduardo recently introduced me to Class::Phrasebook::SQL which allows you to abstract SQL code. It may seem like more work at first, but you get better and faster, and soon you find that HERE DOCS are an unattractive, cludgy solution. This doesn't mean that i won't ever use them again, it just means that i found something better for me.

        (P.S. you can witness some of my older CGI HERE DOC ways over at my Lingua::Ispell review)

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
      Thanks for the template pointer. Templates are an usefull mechanism - of course. But:

      Beware! Templates are great for "slightly dynamical content" - and as such used by me. They are not apropriate for heavy-duty dynamical content.

      Bye
       PetaMem
          All Perl:   MT, NLP, NLU

        Where did you get that information from? Whether the content is "slightly" dynamic or "heavily" dynamic shouldn't matter. Time is spent to load the template and process it, more processing means more CPU time, but this by no means constitutes "not an appropriate solution."

        And the conclusion that is hinted at ... that HERE DOCS are better for "heavily" dynamic content than templating solutions seems very absurd to me - especially when you realize that templating solutions allow you to abstract away components that can be included and cached ... have fun trying to accomplish that with HERE DOCS.

        I really get the impression that most advocates of HERE DOCS have not fully grasped just how much there is to be gained by switching to a templating system. They are both great tools, but the latter is a much better fit for delivering Web Applications.

        UPDATE: (a reply)
        HD with interpolation is indeed already a simple templating system, but it's one that will allow you to paint yourself into a corner. Do yourself a big favor and start using Template modules more than you already might be, then you might realize that HERE DOCS are only good for quick and dirty solutions. (I really believe that you have only a cursory experience with Templating modules - i did a search on your past nodes and none of them mention a single word about Templating except the ones in this thread.) Besides, aren't you just needlessly reinventing the wheel? ;)

        Oh, and believe me ... i do this for a living.

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
Re: I need a title - sucka! :-)
by perrin (Chancellor) on Nov 21, 2003 at 19:47 UTC
    Why not report it to the mod_perl list? There is information here on how to report bugs in mod_perl 2. If you can reduce it to a small test case, you will probably get a good answer.
Re: I need a title - sucka! :-)
by ysth (Canon) on Nov 23, 2003 at 02:36 UTC
    Did you try reintroducing the
    HTML print <<"HTML";
    lines and see if the problem went away again? Did perhaps introduce some other change that causes the problem or mess up the file permissions? Are any errors or warnings logged?