in reply to Eval'ed data loaded from a file?
That's untested, but can't be too far off. This is a simple solution that works for simple problems. It's possible to craft a much nicer regex to catch boundary conditions, but it's difficult.my $text = "Insert $id here!\n"; my %values = ( id => 10 ); $text =~ s/\$(\w+)\b/$values{$1}/g; print $text, "\n";
The second option is an awful abuse of eval I like to call Double Interpolation of a String . I wouldn't recommend it, if you can avoid it.
The third option is to use a templating mechanism from the CPAN, like Text::Interpolate or Text::Template. This is by far the most powerful and safe mechanism. If you're going to be doing this often, time invested in learning one of these modules will pay off nicely.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Eval'ed data loaded from a file?
by dakotas (Initiate) on Dec 28, 2000 at 01:51 UTC |