Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Running a Perl script within a PHP page
Our web site update has been progessing well over the last couple of weeks - you'll probably have notices that most of the pages changed a fortnight ago and the remaining pages are now switching over one or two at a time ... they're typically the more awkward ones!

We've been providing on site training for years .. and quoting on line through a Perl script that is probably the longest standing piece of code on the site. Some of the regular expressions to tell a UK postcode apart from a Canadian one, and to check distances and ferry requirements .... well - let me just say I did NOT fancy updating them to include them within a PHP page.

Solution? Use the "legacy" code and call it in from the new PHP front end. I've amended the Perl slightly to recognise when it's called from the PHP ... additional lines in the Perl to collect incoming parameters:


if ($ARGV[0] eq "php") {
$buffer = join(" ",@ARGV[1..$#ARGV]);
$form{"method"} = "INTERNAL";
} else {
if ($ENV{"REQUEST_METHOD"} eq "POST") {
read(STDIN,$buffer,$ENV{"CONTENT_LENGTH"});
$form{"method"} = "POST";
} else {
$buffer = $ENV{QUERY_STRING};
$form{"method"} = "GET";
}
}


and to return the table as a URL response rather than as HTML:


if ($form{"method"} eq "INTERNAL") {
foreach $key (keys %form) {
# next if ($key eq "price");
$kv = $form{$key};
$kv =~ s/([^a-zA-Z0-9 ])/sprintf("%%%02x",ord($1))/eg;
$kv =~ s/ /+/g;
push @retst,"$key=$kv";
}
$ret = join("&",@retst);
print "$ret\n";
} else {
print "Content-type: text/html\n\n";
print $html;
}


and I've used PHP's shell_exec to run the old Perl code:


$poc = shell_exec("cd $_SERVER[DOCUMENT_ROOT]/../cgi-bin/net; ./excalc.pl php where=$_REQUEST[where]");
$parms = explode("&",$poc);


Try the new quote system
(written 2005-11-12 09:28:31)

 
Associated topics are indexed under
H999 - Additional PHP Material
H107 - String Handling in PHP
P210 - Perl - Topicalization and Special Variables
P221 - Perl on the Web

Back to
New Navigation Aid - Launch of My Wellho
Previous and next
or
Horse's mouth home
Forward to
MySQL - a score of things to remember

Some other Articles
I have a river to cross
Python printf
More spam - a success story
MySQL - a score of things to remember
Running a Perl script within a PHP page
New Navigation Aid - Launch of My Wellho
Being atypical is typical
A new way to get lost
Which MySQL server am I using?
Looking for railway groups and users - Swindon, Salisbury, Southampton
1638 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

© WELL HOUSE CONSULTANTS LTD., 2008: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho