I am helping a friend build a list emailer, for his subscribed users. We where trying to use Mail::Bulkmail by Jim Thomason, but we just could not get it to work, it appears to be having a problem, and he won't respond to any questions, so we decided just to make one.

Here is what I'm doing. He is getting the information in a set pattern, like this example:

$_mergeFields = "##fname##;##lname##;##email##;##phone##;"; $_list_to_send_to = "Richard;Smith;myemail\@testmail.com;8005551212;|T +oby;Johnson;email2\@testmail.com;8885551212|Chanty;Perkins;another\@t +est.com;8665551212;";
There are the same amount of variables in the one that shows the order.

Now the message might be something like this:
$_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 blah blah~;
Of course this email list is just for a business and when the emails go out, it is for the newsletter. So it is not for spam or anything, everyone is double opted in.

Anyhow, I am trying to find the easiest way to take the merge fields and make a hash so that I can then swap out the data something like this:
$_field = 0; %_merData = (); %_mergedData = (); while($_mergeFields) { $_field++; ($_tempVar,$_mergeFields) = split /\;/, $_mergeFields, 2; $_merData{$_field} = $_tempVar; } $_field = 0; while($_list_to_send_to) { ($_tempVar,$_list_to_send_to) = split /\|/, $_list_to_send_to, 2; my $_tempMailMessage = $_message; my $_tempSubject = $_subject; while($_tempVar) { $_field++; ($_tempVar2,$_tempVar) = split /\;/, $_tempVar, 2; $_mergedData{$_field} = $_tempVar2; } foreach $key (key(%_merData)) { $_tempMailMessage =~ s/$_merData{$key}/$_mergedData{$key}/ig; $_tempSubject =~ s/$_merData{$key}/$_mergedData{$key}/ig; if($_merData{$key} =~ /email##$/) { $__to = $_mergedData{$key}; } } go_send_the_message($__to,$_tempSubject,$_tempMailMessage); }
Something like that. That is not the way it should be done, but I don't know another way to do it. Do you? Can you point me in the right direction?
Thank you.

Richard

In reply to 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.