Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Perl script question

1:49 pm on Jul 19, 2010 (gmt 0)

New User

5+ Year Member

joined:Apr 12, 2008
votes: 0

A client of mine had a website developed some years ago and has a very simple CMS which is based on a simple flat file database with a text file and perl script. The client does not want to pay for a rewrite of the site (my experience is in PHP) but wants to make a simple change to the site which I cannot work out with my very limited knowledge of perl.

From what I can see, the perl script does a number of substitutions from the site template. For instance $include[filename.html] entered into the template will mimic the equivalent of an SSI command. This only works when entering a filename. I need to change the script so it also calls in a script (banner script) or url.

How do I change the $include code below to make this happen. I understand I will need to use get and call LWP::Simple; from the beginning of the script, but I'm not sure what I else I need to do.

I thought about adding another variable $geturl and edited / duplicated the $include statement to no avail.

$formTemplate=~s/$geturl\[([^\]]+)]/qx(get ""$1"")/ge;
$formTemplate=~s/\$geturl/ /g;

Extract of script where template substitions are done.

$formTemplate=~s/$include\[([^\]]+)]/qx(cat ""$1"")/ge;
$formTemplate=~s/\$include/ /g;
if ($useCart) {
$formTemplate=~s/\$addbutton/<FORM NAME=\"cart1\">$tmp<\/FORM>/g;

print ($formTemplate);
4:38 pm on July 19, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 31, 2008
votes: 0

You're on the right track.

$formTemplate=~s/$geturl\[([^\]]+)]/qx(get ""$1"")/ge;


and you should be fine. qx would run it as a systemcommand, and get from LWP::Simple is a perlfunction.
It'll require complete URLs (http://host/uri), unlike SSI would. You forgot to escape the closing square brackets and I escaped the $ in the matching part just to make it clear that it's not a variable named $geturl, but it'd work without it, too.