performance Re: string not block Re: SPUG: interpolating into a
string variable
Fred Morris
m3047 at inwa.net
Sun Dec 21 15:09:15 CST 2003
> foreach my $key (keys %subs) {
> $s =~ s/\$$key/$subs{$key}/;
> }
Borrowing from the foregoing (and also from the perldoc, thanks YS-T) I
settled on the following, which seems to be the fastest (notably so) of all
(and also arguably much safer than eval):
$s =~ s/\$(\w+)/defined($subs{$1}) ? $subs{$1} : $1/eg;
--
Fred Morris
fredm3047 at inwa.net (I-ACK)
More information about the spug-list
mailing list