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:
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).<!-- 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 -->
With the left-angle brackets in, I get a result of:
But, if I remove them, I get:sub { $text = ''; if ($h_self{form_data}{page} =~ /confirmation|application/i) { $text .= qq[]; } return $text; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |