I like PHP for its excellent inline integration into standard HTML files,
but I like Perl for its quick-moving syntax and simpler data-processing. To
resolve this deep-seated inner turmoil (oh, the drama) I've been trying to
think of good ways to get Perl code to run inline in a PHP script. Here are
a few of my ideas. If anyone has any further ideas, resources, or knows of
someone else who's solved this already, please do tell...
1.) The simple route: Write the Perl script as a seperate file. Exec() perl
with it.
This would work, but it involves juggling seperate files.
2.) Write the Perl script into a huge Heredoc-formatted string. Proc_open()
perl and send the string to it for execution.
This was the first idea I'd come up with, and the most straightforward,
except for the fact that both Perl and PHP use $ as the variable
descriptor, and I don't know how to turn off variable expansion
(double-quotedness) in Heredoc formatted strings. Is there a way?
3.) Write the Perl script as a specially-marked /* */ comment. Use an
include()d function to read the current file, scan for the marked comments,
and proc_open() feed them to perl.
If I can't find a way to get Heredoc not to interpolate variables, this is
really the best way I can think of to work it. Since Perl only uses # for
comments, there's little chance of */ coming up in the inlined script.
This solution is better, but more complex. It's only dealing with comments,
not code, so there's less chance of tainted PHP input mucking up the works.
On the downside, though, it involves re-reading the PHP file again, as well
as making up and working with nonstandard notation for passing variables
and denoting code.
Related questions:
Are there any ways to denote a large, multiline string in PHP that don't
interpolate variables? Something similar to Perl's __END__ feature,
perhaps?
Also, does anyone know a good "primer" or tutorial that goes over the ins,
outs, and pitfalls of proc_open and piping i/o to processes? I read the
php.net manual, and I get the feeling I should learn a little bit more,
even about piping in general, before attempting to go live with any sort of
proc_open scripts. It doesn't sound all that difficult to bog down a server
with proc_open.
--
-- Rudy Fleminger
-- sp@mmers.and.evil.ones.will.bow-down-to.us
(put "Hey!" in the Subject line for priority processing!)
-- http://www.pixelsaredead.com