Hey all,<br><br>I'm trying to figure something out, but having some trouble. I'm trying to replace multiple patterns via capture buffers, with multiple replacements contained in a hash.<br><br>Looking at the code below, you can see that the patterns I'd like to match are contained in $regex just fine, however I'd like to have mutiple $replacement{$#} 's depending on the number of patterns I'm trying to replace.<br>
<br>==== begin-code ===<br>#!/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";<br>==== end-code ===<br><br><br>Either I'm missing something, or this isn't actually possible, and I'll have to loop through the patterns and replace them individually.<br><br>Thoughts?<br>
<br>-Bobby<br>