Why not turn it around just a little and use a regex to substitute replacement text for key text like this:
use strict; use warnings; my @plates = ( {GIVENNAME => 'Fred', SIRNAME => 'Fredson', AMOUNT => '$10.24'}, {GIVENNAME => 'Joe', SIRNAME => 'Joeson', AMOUNT => '$20.48'}, ); my $text = do {local $/; <DATA>}; for my $plate (@plates) { my $copy = $text; $copy =~ s/$_/$plate->{$_}/g for keys %$plate; print "$copy\n\n"; } __DATA__ Dear GIVENNAME SIRNAME, thanks for your recent contribution if AMOUNT to PerlMonks.
Prints:
Dear Fred Fredson, thanks for your recent contribution if $10.24 to PerlMonks. Dear Joe Joeson, thanks for your recent contribution if $20.48 to PerlMonks.
In reply to Re: Form letters: eval a string to substutite perl variables
by GrandFather
in thread Form letters: eval a string to substutite perl variables
by brycen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |