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

Re: [FWP] Greenhorn coding question



Please note this isn't the correct forum for this type of question.

You didn't read carefully enough.

	If those were both GLOBAL variables, then this would
			   ^^^^^^
	suffice:

	    $text =~ s/\$(\w+)/${$1}/g;  # no /e needed

	But since they are probably LEXICALS, or at least, they could
				    ^^^^^^^^
	be, you'd have to do this:

	    $text =~ s/(\$\w+)/$1/eeg;
	    die if $@;			# needed /ee, not /e

Remove the my's and try again.

<chaim>


>>>>> "RAA" == Roderick A Anderson <raanders@altoplanos.net> writes:

RAA> my $foo = 'foo';
RAA> my $bar = 'bar';

RAA> $text = 'this has a $foo in it and a $bar';
RAA> # Why doesn't this work as advertised with perl 5.004_4 on a stock
RAA> # RedHat Linux 5.2 system with perl 5.004_4.
RAA> $text =~ s/\$(\w+)/${$1}/g;
RAA> print $text;

-- 
Chaim Frenkel					     Nonlinear Knowledge, Inc.
chaimf@pobox.com				               +1-718-236-0183

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