JupiterHost.Net wrote:
Ing. Branislav Gerzo wrote:
I want change [%foo%] to $foo, so I expect in result 'test' as
before defined.

Then you need to do 'no strict;' before you do that:

no strict;
$x =~ s/^\[%([^%]+)%\]$/${$1}/g;
use strict;

Well, a better suggestion IMO would be that $foo is replaced with a hash:

    my %vars = ( foo => 'test' );
    my @bar = ( 'foo', '[%foo%]', 'bar' );
    s/\[%(\w+)%\]/ $vars{$1} or "[%$1%]" /eg for @bar;

Why not just use the Template module, it does what it looks like
you're trying to do already without reinventing the wheel :)

Yeah, that's another option.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to