As f00li5h pointed out, the best approach would be to use a templating module.

To pick up where he left off and provide an example of how you can use split to separate your input data, I submit the following code:

use strict; use warnings; my $_mergeFields = "##fname##;##lname##;##email##;##phone##;"; my $_list_to_send_to = "Richard;Smith;myemail\@testmail.com;8005551212 +;|Toby;Johnson;email2\@testmail.com;8885551212|Chanty;Perkins;another +\@test.com;8665551212;"; my $_message = qq~ Hello ##fname## how are you today? Hopefully your day is going well. I + am the list server for some company, blah blah blah, and I have list +ed your phone number as ##phone##. Well, here is all the data I have +for you: Name: ##fname## ##lname## Phone: ##phone## email: ##email## So I just wanted to say thank you for signing up yesterday to get emai +ls from us, and if you don't want to receive any more just click the +link below and we won't send any more out. blah blah ~; my @fields = split( ';', $_mergeFields ); my @recipients = split( '\|', $_list_to_send_to ); foreach my $recipient ( @recipients ) { my @recip_data = split( ';', $recipient ); my $recip_msg = $_message; foreach my $field ( @fields ) { my $value = shift @recip_data; $recip_msg =~ s/$field/$value/g; } print $recip_msg, "\n\n"; }

Note: Don't use this in production - use a templating module.


In reply to Re: merging two fields of data into one hash or array by bobf
in thread merging two fields of data into one hash or array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.