Thanks for the help. I just got back on-line. I'll give these a try.
Thanks again !
"Randy W. Sims" <[EMAIL PROTECTED]>
01/25/2004 03:19 PM
To
Jan Eden <[EMAIL PROTECTED]>
cc
[EMAIL PROTECTED], Perl Lists <[EMAIL PROTECTED]>
Subject
Re: How to put a variable value into a text file
On 1/25/2004 3:02 PM, Jan Eden wrote:
> Hi Stuart,
>
> @testarray gets the content of testmessage.txt, which contains the
string '$name'. You cannot manipulate this string by setting the variable
$name. You could do:
>
> @testarray =~ s/\$name/$name/g;
>
> which will replace the literal string '$name' using your variable's
content.
or more generally
#!perl
use strict;
use warnings;
my $name = "Randy";
while (my $line = <DATA>) {
$line =~ s/[^\\](\$\w+)\W/eval $1/eg;
print $line;
}
__DATA__
My name is $name.
For each line we read in, we look for any occurence of a unescaped
dollar sign (i.e. not preceeded by a backslash) followed by any
characters valid in a variable name up to any non-valid character. We
then substitute that for the current value of that variable within our
program.
Regards,
Randy.