Discussion Locked

PERL: Evaluate $'s from external files?

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm writing a Perl script that reads HTML code from a text file, evaluates $ variables in the HTML page, and then prints the page to the browser. Here's my problem:

Let's say my HTML page contains the variable $a and my Perl script defines $a = 1. When I print the code to the browser, Perl prints "$a" to the screen instead of evaluating the string and printing "1".

How can I have Perl open an HTML file containing string variables, evaluate the variables and then print the HTML to the browser?

1 reply

by niki_a

Perl, as with most programming languages, requires you to read a text value into a variable. For example:

open (MYFILE, "< e:/path/to/myfile.htm") ;
my $a = ;
chop($a)
close(MYFILE) ;

However, to get some of the flexibility you areprobably looking for, you would probably want to include hidden (form) field values in your HTML file. Then in Perl you would make use of CGI module:

use CGI ;
my $q = new CGI;
my $a = $q->param('my_a_value');

Where 'my_a_value' is the nameof the hidden field, i.e:

That would allow perl to get the values you need it to process. See CGI.pm POD for more info on how to implement.

This discussion is closed to new replies.