Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Perl script question

     

helensimons

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

5+ Year Member



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.

$dateCreated=&getDate($id);
$formTemplate=~s/(\$if[^\}]*\})/&getIf($1)/ge;
$formTemplate=~s/\$data\[([0-9]+)\]/$data[$1]/g;
$formTemplate=~s/\$escape\[([0-9]+)\]/$escape[$1]/g;
$formTemplate=~s/\$fields\[([0-9]+)\]/$fields[$1]/g;
$formTemplate=~s/$include\[([^\]]+)]/qx(cat ""$1"")/ge;
$formTemplate=~s/\$include/ /g;
$formTemplate=~s/\$id/$id/g;
$formTemplate=~s/\$datecreated/$dateCreated/g;
$formTemplate=~s/\$membername/$owner/g;
if ($useCart) {
$tmp=&wtcart::addButton("cart1");
$formTemplate=~s/\$addbutton/<FORM NAME=\"cart1\">$tmp<\/FORM>/g;
}

print ($formTemplate);
};

janharders

4:38 pm on Jul 19, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You're on the right track.
change

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

to
$formTemplate=~s/\$geturl\[([^\]]+)\]/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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month