in reply to Re: Re: search replace (interpolation)
in thread search replace (interpolation)

So put the information you retrieve from the database in a hash with the keys FULLFROM, FROM, FNAME, LNAME, EMAIL, and SUBJECT.
my %header_line = read_header_or_something($mail_file); while(my %recipient_info = get_info_from_db()) { while(my ($header, $value) = each %header_line) { $value =~ s/__(.+?)__/$recipient_info{$1}/g; print "$header: $value\n"; } }

And I hope you're not sending the mail to people who haven't opted in on their own.. :)

Update: doh, silly me for forgetting to mention you would be better off with a templating system. Unlike UnderMine, I would propose the more generic and powerful Template Toolkit though.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^4: search replace (interpolation)
by UnderMine (Friar) on Dec 16, 2002 at 20:50 UTC
    This sounds like a perfect case for using a standard templating module. Using say HTML::Template you end up with very simple template and perl coding.
    Message-ID: <1039751337.22128@idhost> Content-Transfer-Encoding: 8bit Content-Type: multipart/alternative; boundary="_----------=_1039751337 +22128" MIME-Version: 1.0 Date: Thu, 12 Dec 2002 19:48:57 PST From: <!-- TMPL_VAR NAME=FULLFROM --> <<!-- TMPL_VAR NAME=FROM -->> To: <!-- TMPL_VAR NAME=FNAME --> <!-- TMPL_VAR NAME=LNAME --> <<!-- TM +PL_VAR NAME=EMAIL -->> Subject: <!-- TMPL_VAR NAME=SUBJECT --> Precedence: bulk
    then the perl is trivial
    while(my %recipient_info = get_info_from_db()) { my $template = HTML::Template->new(filename => 'email.tmpl'); $template->param(%recipient_info); print $template->output(); }
    Hope this helps
    UnderMine
Re: Re^3: search replace (interpolation)
by Anonymous Monk on Dec 16, 2002 at 21:44 UTC
    thanks all for the help.