[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] reading variables from files



Hello there,

I have a problem trying to read in a variable from a file with variables in
it.

For example, one can do this:

$myVar = "Hi There";

print "I'm going to print out the var $myVar\n";

This will result in a list that reads:

I'm going to print out the var Hi There

What I want to be able to do is have a text file that contains:

"I'm going to print out the var $myVar\n"

Read it into my script, and when I print it from the script have it subsitute
the variable. Currently, I can't get it to do that. Here's how I'm reading in
the file:

$myVar = "Hi There";
$myFile = "HD:inputfile.txt";
open (MYINPUT, $myFile) || die "Can't open file: $myFile\n";
@myData = <MYINPUT>;
foreach (@myData) { $Whattoprint = $Whattoprint . $_;};
close (MYINPUT);
print $Whattoprint;

1) Can I do what I want to do? The reason I want to do this is I'm creating a
form where the people using it need to edit the text, but variables I'm
pulling from a database are sprinkled throughout the text. I don't want them
to have to edit the script.

2) Is there an easier way to read a glob of text into a variable?

Thanks,
Jim Kateley
kateley@apple.com