Thanks guys, this looks exactly like what I was looking for!<br><br><br><div class="gmail_quote">On Wed, Dec 22, 2010 at 10:54 AM, Mike Stok <span dir="ltr"><<a href="mailto:mike@stok.ca">mike@stok.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="word-wrap: break-word;">Maybe you want the e modifier:<div><br></div><div><div class="im">
<div>#!/usr/bin/env perl</div><div>use strict;</div><div>use warnings;</div><div><br></div></div><div>my %replacement = (</div><div> a => 'd',</div><div> b => 'e',</div><div> c => 'f',</div>
<div>);</div><div><br></div><div># this needs to be done with more care as you want to make sure that</div><div># abc appears before ab, but you get the idea...</div><div>my $pattern = join('|', map { quotemeta } keys %replacement);</div>
<div>print "pattern = $pattern\n";</div><div class="im"><div><br></div><div>my $line = "*!*!* a *!*!* b *!*!* c *!*!*";</div></div><div>$line =~ s/($pattern)/$replacement{$1}/ge;</div><div><br></div><div>
print $line."\n"; </div><div>__END__</div><div><br></div><div>produces</div><div><br></div><div><div>ratdog:tmp mike$ perl <a href="http://try.pl" target="_blank">try.pl</a></div><div>pattern = c|a|b</div>
<div>*!*!* d *!*!* e *!*!* f *!*!*</div></div><div class="im"><div><br></div><div><div>On Dec 22, 2010, at 10:44 AM, J. Bobby Lopez wrote:</div><br><blockquote type="cite">#!/usr/bin/env perl<br>use strict;<br>use warnings;<br>
<br>my %replacement;<br>$replacement{'a'} = 'd';<br>$replacement{'b'} = 'e';<br>$replacement{'c'} = 'f';<br><br>my $line = "*!*!* a *!*!* b *!*!* c *!*!*";<br><br>
#my $pattern = '(a)|(b)|(c)'; # Doesn't work, only matches first pattern<br>my $pattern = '(a).*(b).*(c)'; # kinda/sorta, replaces stuff between patterns also<br><br>#$line =~ s/$pattern/$replacement{$1}/; # <-- here's where I'm having difficulty<br>
$line =~ s/$pattern/$replacement{$1} $replacement{$2} $replacement{$3}/; # kinda/sorta<br><br>#$line =~ m/$pattern/;<br>#print "$1, $2, $3\n";<br><br>print $line."\n";</blockquote></div><br></div><div>
<div style="margin: 0px; font-size: 12px;">-- </div><div style="margin: 0px; font-size: 12px;"><br></div><div style="margin: 0px; font-size: 12px;">Mike Stok <<a href="mailto:mike@stok.ca" target="_blank">mike@stok.ca</a>></div>
<div style="margin: 0px; font-size: 12px;"><a href="http://www.stok.ca/%7Emike/" target="_blank">http://www.stok.ca/~mike/</a></div><div style="margin: 0px; font-size: 12px;"><br></div><div style="margin: 0px; font-size: 12px;">
The "`Stok' disclaimers" apply.</div><div style="font-size: 12px;"><br></div><div style="font-size: 12px;"><br></div><span style="font-size: 12px;"><br></span>
</div>
<br></div></div></blockquote></div><br>