473,418 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Perl inline with PHP, a few ideas. Also: Multiline strings? Proc_open() tuts?

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
Jul 17 '05 #1
4 3134
In article <1n******************************@40tude.net>,
FLEB <so*********@mmers.and.evil.ones.will.bow-down-to.us> wrote:
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.


What webserver are you running? Have you tried mod_perl? mod_perl enables
inline perl code in HTML document much like how PHP functions.

Difference is that PHP has a multitude of HTML/Web-specific functions that Perl
lack (or need to be added) which is why I have switched full-time to PHP from
being a SSI/CGI kind of guy in the past.

And yes, I miss $_, among a series of things, as well. :-D

--
Sandman[.net]
Jul 17 '05 #2
Regarding this well-known quote, often attributed to FLEB's famous "Wed, 23
Jun 2004 20:21:25 -0400" speech:
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...

--snip--
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.


--snip--

Well, late last night I tried working this out. Here's what I came up with:
http://php.pixelsaredead.com/inline-perl/show-me.php

I'm probably going to completely overhaul everything except the basic idea.
I'm going to drop the interpreter="whatever" in favor of just reading a
shebang (#!) line from the comment. Right now the interpreter="" doesn't
actually specify anything (It just defaults to perl). It also needs a good
way to pass variables back and forth. Still, though, I like where this is
going.

--
-- 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
Jul 17 '05 #3
On Wed, 23 Jun 2004 20:21:25 -0400, FLEB
<so*********@mmers.and.evil.ones.will.bow-down-to.us> wrote:
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.

2.) Write the Perl script into a huge Heredoc-formatted string. Proc_open()
perl and send the string to it for execution.

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.


(4) The 'proper' way but also by far the most work - probably a ridiculous
amount - embed a Perl interpreter in PHP, interfacing the two with a PHP
extension module, to avoid the startup costs of spawning a new Perl interpreter
per request.

http://www.perldoc.com/perl5.8.0/pod/perlembed.html

Implmentation details left as an excercise for the reader ;-)

Then again, this is basically re-inventing mod_perl, except loading it from
PHP rather than directly from Apache.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #4
Regarding this well-known quote, often attributed to Andy Hassall's famous
"Thu, 24 Jun 2004 23:06:36 +0100" speech:
On Wed, 23 Jun 2004 20:21:25 -0400, FLEB
<so*********@mmers.and.evil.ones.will.bow-down-to.us> wrote:
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.

-- snip 3 ideas --
(4) The 'proper' way but also by far the most work - probably a ridiculous
amount - embed a Perl interpreter in PHP, interfacing the two with a PHP
extension module, to avoid the startup costs of spawning a new Perl interpreter
per request.

http://www.perldoc.com/perl5.8.0/pod/perlembed.html

Implmentation details left as an excercise for the reader ;-)

Then again, this is basically re-inventing mod_perl, except loading it from
PHP rather than directly from Apache.


Yeah... I'm nowhere *near* that hardcore :).

--
-- 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
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sandman | last post by:
The subject says it all. I am doing a: I have a perl script in which I am using a ReadParse routine that parses the $ENV{'QUERY_STRING'} or $ENV{'CONTENT_LENGTH'} which are two variables passed...
0
by: Rasmus Fogh | last post by:
Dear All, I need a way of writing strings or arbitrary Python code that will a) allow the strings to be read again unchanged (like repr) b) write multiline strings as multiline strings instead...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
46
by: Reinhold Birkenfeld | last post by:
Hello, another Perl/Python question: the subject says it all. Perl is going to change dramatically to become a more powerful and easier to (read|write) language. Is Python taking a similar...
1
by: Bryan Krone | last post by:
I have a stream of data comming off a serial port at 19200. I am wondering what is the most efficient way to grep through the data in realtime? I have 20 or so different strings I need to find. All...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
17
by: beginner | last post by:
Hi All, This is just a very simple question about a python trick. In perl, I can write __END__ in a file and the perl interpreter will ignore everything below that line. This is very handy...
2
by: kimonp | last post by:
I am running on windows XP with a fresh install of wamp5 (1.7.2) and mediawiki. I am trying to call a perl function from within php using proc_open. The perl script is being executed and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.