Qukz has asked for the wisdom of the Perl Monks concerning the following question:
I have some boilerplate text files with some variables I'd like to substitute. I'd then like to create new files with the appropriate substitutions based on those; for example (one of the boilerplate text files):
Hello $FIRST_NAME. I'm writing on behalf of $COMPANY...
How would I go about using those files to create new files with the substituted values, so the new file would then be
Hello James. I'm writing on behalf of SoftLayer...
The following works
my $outfile = "new.txt"; open (OUTFILE, ">> $outfile") || die "Can't open $outfile\n"; print OUTFILE "\n"; print OUTFILE "Hello $FIRST_NAME.\n"; print OUTFILE "\n"; print OUTFILE "I'm writing on behalf of $COMPANY...";
But I can't figure out how to do the above while keeping the boilerplate text files seperate from the script itself and still printing the substituted variables rather than the literal names of the variables.
Any help would be greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading from/writing to files with variables substitutions
by aitap (Curate) on Mar 28, 2013 at 07:36 UTC | |
|
Re: Reading from/writing to files with variables substitutions
by Anonymous Monk on Mar 28, 2013 at 07:34 UTC | |
|
Re: Reading from/writing to files with variables substitutions
by 2teez (Vicar) on Mar 28, 2013 at 08:29 UTC | |
|
Re: Reading from/writing to files with variables substitutions
by BillKSmith (Monsignor) on Mar 28, 2013 at 15:24 UTC | |
|
Re: Reading from/writing to files with variables substitutions
by perlaintdead (Scribe) on Mar 28, 2013 at 23:58 UTC |