I have a module that performs parallel substitutions on a string, as
in:

   $str = subst $str,
          qr/foo/ => 'bar',
          qr/bar/ => 'baz',
          qr/baz/ => 'foo';

Just as if it were typed:

   $str =~ s/(foo|bar|baz)/$1 eq 'foo' ? 'bar' :
                           $1 eq 'bar' ? 'baz' :
                           $1 eq 'baz' ? 'foo'/g;

For any set of regexes you want, handling $1,$2 and all that
correctly.  I call it Regexp::Subst::Parallel at the moment.  Does
anyone have any better ideas for the name of such a module?

Additionally, can someone think of a better calling convention to use
than the one illustrated above?  I'm running into problems with other
kinds of interpolations:

  $str = substr,
         qr/(the contractee)/i => "\$1, $name, ",
         qr/(the contractor)/i => "\$1, $name2, ";

That works, replacing \$1 with "the contractee" in whatever case it
was.  The problem is, that for a literal $ with other interpolations,
it would have to be "\\\$", which is by no means pretty.  Any ideas?

Thanks,
Luke

Reply via email to