SPUG: interpolating into a string variable

Brian Hatch bri at ifokr.org
Sun Dec 21 00:13:48 CST 2003



> Let's say we have a string variable. In practice it's read in from a file,
> but it could be a constant. And what we want to do is force interpolation
> into it before we use it for something like... ooooh, a regex. So,
> something like this:
> 
> 
>     my $foo_str = 'foo';
> 
>     my $expr = 'a $foo_str happens here';
> 
>     my $interpolated_expr = something magic happens to $expr;
> 
> and then if you print "$interpolated_expr\n"; you would get
> 
>     a foo happens here

my $interpolated_expr;

eval "\$interpolated_expr = \"$expr\"; ";

(Hope I didn't miss any backslashes.)

--
Brian Hatch                  Failure is not an option.
   Systems and                It comes preinstalled
   Security Engineer          with the software.
http://www.ifokr.org/bri/

Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/spug-list/attachments/20031220/d795062d/attachment.bin


More information about the spug-list mailing list