Greetings Wise Ones of Perl -

I have arrived at the end of my rope (a very short one probably) trying to find an answer to the conundrum I've encountered. It involves parsing files, printing what is found and even executing "embedded" anonymous subs.

I am parsing two files to create a single .html page. The first is a template containing a header, navigation and a footer, while the second contains the content of the page. I have a script that reads in the template and, when it encounters <!-- Begin main body block -->, opens the second file and recursively reads it into the space between <!-- Begin main body block --> and <!-- End main body block -->. This works very well.

While parsing these files, it is possible to encounter another commented block which contains an anonymous subroutine. The code snippet to locate the perl code looks like this:

UPDATE -

As I noted in my response to davidrw, I did do something incredibly stupid while trying to be smart. I was using the shebang line of #!/usr/bin/perl -wT and not untainting the code I was reading in from the other files.

@*&^ newbies !!!

if (m/\<!-- Begin Perl Block --\>/i) { my $perlcode = ''; # Pull in all the perl code while (<PAGE>) { # This is the end of the block last if m/\<!-- End Perl Block --\>/i; $perlcode .= $_; } # Execute the anonymous sub $_ = &{eval $perlcode;}; }

The portion to be parsed may look something like:

<!-- 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 -->
As you can see, this portion of HTML code would be inserted into the web page if $h_self{form_data}{page} has a particular value. This is where I am having difficulty. I've found that the '<' in front of <style> and </style> are causing everything between to be ignored. I have tried to escape them with '\' and '\\' and '\\\', but to no avail(Yes the final measure was desperate).

With the left-angle brackets in, I get a result of:

sub { $text = ''; if ($h_self{form_data}{page} =~ /confirmation|application/i) { $text .= qq[]; } return $text; }
But, if I remove them, I get:
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; }

So, my question is two-fold:

1. Why does the left-angle bracket cause this behavior? and

2. How do I get around it?

UPDATE

1. The left-angle bracket doesn't cause this behavior! and

2. I get around it by paying closer attention to the pragmas I'm using!!

Please help. me find my backside

In humble supplication - (sorry to have wasted your time, but thank you so much for the help.)

Ron

READMORE tags added by Arunbear


In reply to < Woes by rongoral

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.