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

[MacPerl] Re: Reading variables from files



> 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.
> 
> 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?
> 

Here's what we do....

#!usr/bin/perl

$foo = "../images/image.gif"

open(TEXT, "foo.html");
        while (<TEXT>) {        
                if( /\$foo/) {
                        s/\$foo/$foo/;
                }               
        print;
        }
        close (TEXT);
} 

        ......

foo.html

<HTML>
<IMG SRC = "$foo"> Here's my image
</HTML>

This format also allows you to put your html documents and gifs into 
secure folders
outside your http root.

thanks
ed