[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Greenhorn coding question



On Tue, Jul 06, 1999 at 10:58:03AM -0700, Roderick A. Anderson wrote:
> my $foo = 'foo';
> my $bar = 'bar';
> 
> # From 'man perlfaq4'
> $text = 'this has a $foo in it and a $bar';
> 
> # Why doesn't this work as advertised with perl 5.004_4 on a stock
> # RedHat Linux 5.2 system with perl 5.004_4.
> $text =~ s/\$(\w+)/${$1}/g;
> 
> print $text;
> 
> # Comes out as this has a  in it and

You can't have symbolic references to lexical variables.  Lexical variables
are not stored in the symbol table.


use vars qw($foo $bar);
$foo = 'foo';
$bar = 'bar';

# as before


Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe