JN> Then you need to do 'no strict;' before you do that: JN> no strict; JN> $x =~ s/^\[%([^%]+)%\]$/${$1}/g; JN> use strict;
I think turning off strict is bad idea, also, that doesn't work either.
It is a bad idea but it is what needs done to use soft references like you are doing.
JN> Why not just use the Template module, it does what it looks like you're JN> trying to do already without reinventing the wheel :)
I like to do that without that module, it can't be so hard...
Probably not but I can't figure out what you're trying to do, it looks a lot like templateing :)
JN> or if its literally foo JN> then JN> for(@bar) { s/\[\%foo\%\]/\Q$foo\E/g; }
it isn't of course only foo. I am parsing ini file, which looks like:
In that case a rethink of what you're trying to do and the current paradigm may help.
Are you sure an array of strings that may or may not have a variable named after tehm is a good idea?
If you had a hash you could do somthing like this:
my %template_stuff = ( foo => 'Joe Mama', bar => 'Hello World' ); my @data = qw(foo [%foo%] [%bar%]); for(@data) { print "Before $_\n"; my ($possible_key) = $_ =~ m/\[\%(\w+)\%\]/; if(exists $template_stuff{$possible_key}) { s/\Q[%$possible_key%]\E/\Q$template_stuff{$possible_key}\E/g; } print "After $_\n"; }
HTH :)
Lee.M - JupiterHost.Net
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>