in reply to Making perl evaluate a variable with a string
to do? Please provide a sample of the output you're trying to get.$a=1; $b=2; .... while ($line = <INFILE>) { chomp($line); # contains $a, $b print "$line\n"; #prints "$a" "$b"
It's not clear what you are trying to achieve. See I know what I mean. Why don't you?
If you read text to print it later, you print text. If you want to replace text (eg. "$a" with "1"), do so with s/\$a/1/ - see perlre.
If you want perl to evaluate the file, say so with eval, do or require. Evaluating a file whilst reading it linewise is tricky and outright impossible if those lines aren't self-contained perl statements (e.g. if the file contains control structures spanning several lines).
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Making perl evaluate a variable with a string
by moked (Beadle) on Apr 01, 2007 at 15:57 UTC | |
by klekker (Pilgrim) on Apr 01, 2007 at 16:20 UTC |