-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

First, I have a solution.  But it's ugly as sin, so I was curious if 
there was a better one.

I want someone to call a function with two arguments, a regular 
expression and the expression to change it into.  So calling:
        foo('.(b).', 'the middle letter was $1!')

would result in the string
        "the middle letter was b!"

The solution is:
        $a =~ s/$b/eval("\"$c\"")/e;

as can be seen in this test program:

#!/usr/bin/perl

$a = "abc";
$b = ".(b).";
$c = "the middle letter was \$1!";
$a =~ s/$b/eval("\"$c\"")/e;
print "$a\n";


Anyone have a better way?
- -- 

Kee Hinckley - Somewhere.Com, LLC - Cyberspace Architects
Now Playing - Folk, Rock, odd stuff - http://www.somewhere.com/playlist.cgi

I'm not sure which upsets me more: that people are so unwilling to accept
responsibility for their own actions, or that they are so eager to regulate
everyone else's.

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>

iQA/AwUBOmXwyiZsPfdw+r2CEQLnCwCfbOz2Ph/GwyqM36opZyPYq1O/P6cAoPRq
5JPVQsqJDnoDnWXOjyoj47KC
=Nvy8
-----END PGP SIGNATURE-----

Reply via email to