in reply to Uer Perl Variable in txt file
Using a hash instead of variables is safer (no eval needed). Something like this:
#!/usr/bin/perl use warnings; use strict; my %replace = (name => 'Joe', fun => 'a game'); while (<DATA>) { for my $key (keys %replace) { s/\$$key/$replace{$key}/g; } print; } __DATA__ Hullo $name, are you ready for $fun?
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Uer Perl Variable in file
by moritz (Cardinal) on Aug 06, 2012 at 13:59 UTC | |
by tinita (Parson) on Aug 06, 2012 at 14:24 UTC |
In Section
Seekers of Perl Wisdom