I would second scooterm's comment. In addition, the answers above dont really solve your problem:
- You dont want to be cutting and pasting between an HTML editor and Perl editor
- You dont want to be heavily modifying the HTML (adding special variable tags or whatever)
- You do not want to be heavily modifying the existing Perl code (rewriting to a module API or adding half-assed templating subroutines)
To sum up, by the time perl starts executing you want it to run exactly as your program does now. But for you (while developing) you want the html fragments in their own file, to edit with Frontpage and use Perl's existing $variable syntax.
Consider using a source filter.
package Insert;
use Filter::Simple;
sub slurp
{
my $file = shift;
my ($str, $in);
open($in, $file) or die $!;
local $/ = undef;
$str = <$in>;
close $in;
return $str;
}
FILTER
{
1 while $_ =~ s/INSERT\(\s*?["']?([^"']*?)["']?\s*?\)/slurp($1)/e;
+
}
1;
This will paste the contents of files into your script before perl begins executing.
- Save the above code with the rest of your program as Insert.pm
- add use Insert; to the top of your script
- Cut the contents of each heredoc and paste into a new file
- Replace the heredoc contents with INSERT("/path/to/that/file")
So this
my $variable = "World!";
print <<EOT;
Hello $variable
EOT
would become this
use Insert;
my $variable = "World!";
print <<EOT;
INSERT("includeme.txt")
EOT
With the file
includeme.txt being
Hello $variable
This will do what you want - but be careful what you wish for.
At least you can concentrate on hacking the HTML rather than adapting existing code to an API or debugging a broken wheel.
Once you get the HTML the way you want it, you can simply paste it back into the code to get better performance.
time was, I could move my arms like a bird and...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.