Jeff, et al --
...and then Jeff 'japhy' Pinyan said...
%
% On Aug 17, David T-G said:
%
% >% Yes. I'm using s{}{} instead of s///. I prefer the use of {} delimiters
% >% when I'm doing a s///e, because it better represents the "code" aspect of
% >% the replacement.
% >
% >Ohhhhhhh... Slick. Can I use () or perhaps even [] as well?
%
% Indeed, and <> too. Those are the four pairs of, err, pairing delimiters.
Wow. Very cool. I was worried about [] and never considered <> because
they usually have roles, but I guess then that all four do :-)
% The others (like / and % and !) match themselves. And you'll notice that
% I didn't have to \ the {'s and }'s inside the code. That's because when
% using paired delimiters, you can nest them (properly) without distress.
Cool! *Very* good to know.
% Any of them that WOULD disrupt the nesting DO need to be backslashed.
OK. But we can plan for that and use a non-conflicting pair :-)
%
% > 63 sub parseit
% > 64 {
% > 65 my ($t,$u) = @_ ;
% > 66 my %template = %$t ;
% > 67 my %userdata = %$u ;
% > 68 my $body =
% > 69 $userdata{flag} ?
% > 70 $template{HTML} : $template{ASCII} ;
% > 71 my $keys = join('|',map(quotemeta,keys(%userdata))) ;
% > 72 $body =~ s/#($keys)#/$userdata{$1}/g ;
% > 73 return $body ;
% > 74 }
%
% Nicely done.
Thanks!
%
% >and works dandily :-) I could probably clean up the two hashes I send to
% >parseit. Hey, I wonder if
% >
% > my ($template{ASCII},$template{HTML},
% > $userdata{flag},$userdata{EMAIL},$userdata{NAME_FIRST},
% > $userdata{NAME_LAST}) = @row
% >
% >because each of those is a single value...
%
% Sadly, no, but you're close. You can't use my() on a PART of a hash or
Ahhhh...
% array. You'd have to declare the hashes first, and then populate them.
OK.
%
% my (%tmplate, %userdata);
% (
% @template{qw(ASCII, HTML)},
% @userdata{qw(flag EMAIL NAME_FIRST NAME_LAST)},
Oooh, I like the slicing. That's even more clean.
% ) = @row;
%
% That's perfectly fine; use it if you feel it cuts down on clutter and is
% still comprehensible.
Indeed. I think I might.
...
Hmmm... Well, it wasn't happy. I got the assignment right, it seems,
but then I can't use it:
...
42 ### loop thru list
43 while ( my @row = $result->fetchrow_array )
44 {
45 # my ($ascii, $html, $flag, $email, $fn, $ln) = @row ; # break out vars
46 # my $body = # generate message body
47 # parseit
48 # (
49 # {ASCII=>$ascii,HTML=>$html}, # send templates
50 # {flag=>$flag,EMAIL=>$email,NAME_FIRST=>$fn,NAME_LAST=>$ln} # send
user data
51 # ) ;
52 my (%template,%userdata) ; # we must predefine if
we're to be slick like this
53 (@template{qw(ASCII HTML)}, # message template
54 @userdata{qw(flag EMAIL NAME_FIRST NAME_LAST)}) # user data
55 = @row ;
56 my $body = parseit(%template,%userdata) ; # now go and parse
57 print "I got '$body' for .$row[3].\n"; ###
58 }
...
67 # parse function
68 sub parseit # parse template and
replace user data
69 {
70 my ($t,$u) = @_ ; # get params (pointers)
71 my %template = %$t ; # copy from reference
to local hash
72 my %userdata = %$u ; # copy from reference
to local hash
73 my $body = # set body
74 $userdata{flag} ? # is the HTML flag set?
75 $template{HTML} : $template{ASCII} ; # spit out whichever
is right
76 my $keys = join('|',map(quotemeta,keys(%userdata))) ; # pull keys FN,LN,...
and turn into string FN|LN|...
77 $body =~ s/#($keys)#/$userdata{$1}/g ; # do the magic
replacing
78 return $body ; # send it back up
79 }
...
# !%
Can't use string ("ASCII") as a HASH ref while "strict refs" in use at
/home/admin/bin/massmail-send-script.pl line 71.
Any thoughts? Maybe I have to actually pass a reference instead of
successfully passing a hash (could I have done that?)...
%
% I'd like to say that it's a pleasure helping you. You know what you want
You'd like to ... but you can't? ;-)
% to do, you know how to explain it, you show your code, you're receptive to
Ah, *that* is just a bit of "knowing how to ask a question" :-)
% advice and pointers to documentation, and you have a very good attitude.
Thanks! Heck, the perl that I've forgotten would fill half a book; the
perl I haven't learned would fill a library! It pays to listen to others,
especially when in need of assistance :-)
%
% Thank you for making my Perl day more bearable.
Thank *you* for all of your help! :-)
HAND
:-D
--
David T-G * There is too much animal courage in
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
pgp00000.pgp
Description: PGP signature
