[Chicago-talk] using a regex in a variable
Steven Lembark
lembark at jeeves.wrkhors.com
Mon Oct 27 07:33:14 CST 2003
--On Friday, October 24, 2003 08:54:54 -0500 Jay Strauss <me at heyjay.com>
wrote:
> Hi,
>
> If I have:
>
> my $regex = 's/$/_addsomejunk/';
> my $str = 'something';
>
> how do I use the $regex on $str to turn $str into "something_addsomejunk";
It doesn't work that way -- unless you intend to eval the regex.
You can use:
$added = '_blah';
$str =~ s/$/$blah/;
In this case, however, since you are replacing the end of a string
why not just use:
$str .= $added;
to append it?
--
Steven Lembark 2930 W. Palmer
Workhorse Computing Chicago, IL 60647
+1 888 910 1206
More information about the Chicago-talk
mailing list