in reply to < Woes

First, I have to ask why (maybe there's a reason e.g. legacy, install/enviroment issues, etc) you're going with this home grown solution and not Template::Toolkit or Mason which both support include files and embedded perl.

As for the < causing problems, that's curious.. First thought of a work-around is to use a here-doc instead of qq[].

For the explaination I think that this perldoc perlop snippet holds the answer (hopefully someone more knowledgeable of qq[] can elaborate):

   Finding the end
   The first pass is finding the end of the quoted construct, whether it be a multicharacter delimiter
    ""\nEOF\n"" in the "<<EOF" construct, a "/" that terminates a "qq//" construct, a "]" which terminates
    "qq[]" construct, or a ">" which terminates a fileglob started with "<".


Update: I'm having troubling reproducing the error -- do you have a simple test case (e.g. one that reads from <DATA>)? The following script works for me:
#!/usr/bin/perl use strict; use warnings; my $text; my %h_self = (form_data =>{page=>'confirmation'}); while(<DATA>){ if (m/\<!-- Begin Perl Block --\>/i) { my $perlcode = ''; # Pull in all the perl code while (<DATA>) { # This is the end of the block last if m/\<!-- End Perl Block --\>/i; $perlcode .= $_; } # Execute the anonymous sub warn &{eval $perlcode;}; } } __DATA__ BLAH <!-- Begin Perl Block --> sub { $text = ''; if ($h_self{form_data}{page} =~ /confirmation|application/i) { $text .= qq[<style type="text/css"> body {font-size: 8pt;font-family: Arial, Helvetica;} table {font-size: 8pt;font-family: Arial, Helvetica;} tr {font-size: 8pt;font-family: Arial, Helvetica;} td {font-size: 8pt;font-family: Arial, Helvetica;} select {font-size: 8pt;font-family: Arial, Helvetica;} input {font-size: 8pt;font-family: Arial, Helvetica;} form {font-size: 8pt;font-family: Arial, Helvetica;} div {font-size: 8pt;font-family: Arial, Helvetica;} p {font-size: 8pt;font-family: Arial, Helvetica;} .red {font-weight: bold;font-size: 10pt;color: red;text-align:right;} .black {font-weight: bold;font-size: 10pt;color: black;text-align:righ +t;} .backfill {background-color:003399;text-align:center;color:white;font- +weight:bold;border: 1px solid white;} .cell {border: 1px solid white;} .edit {width: 50;} </style>]; } return $text; } <!-- End Perl Block --> STUFF

Replies are listed 'Best First'.
RE:RE: < Woes
by rongoral (Beadle) on Jul 03, 2005 at 21:47 UTC

    Your bit of code works exactly as I would like mine to. =( I've put it into an executable and it does what I expect. However, if I gut the function in the original cgi script and put your code in, it fails. In fact, nothing is printed after the eval statement.

    I have found, however, that if I substitute &lt; for < in the file and then s/\&lt;/\</g; after it is pulled out, the text will then take the form that I want. Now, though as I stated above, I find that the real failure is in the eval portion. But, I cannot pull out the reason using $@. I think that it fails, but it will not say why.

    I am not using Template::Toolkit or the like because I don't know what is going to be on a particular server. I am usually writing code for people who are paying to be hosted on someone's server and I cannot always be sure what is and is not installed there. Likewise, I don't have access to SSH their sites. So, I try to keep it as "pure" as possible. Of course, as anyone will correctly point out, this means that I have to wade through my own errors before the code becomes fit for consumption.

    I must be doing something incredibly stupid. But, I can't see it.