Well the following works for everything except $foo
#!/usr/bin/perl -w
use strict;
my @tests;
push (@tests, q($foo));
push (@tests, q($foo[0]));
push (@tests, q($foo{bar}));
push (@tests, q($foo{'bar'}));
my $foo = 'scalarfoo';
my @foo = qw(arrayfoo);
my %foo = ( 'bar' => 'hashfoo' );
foreach my $foo (@tests) {
$foo =~ s/(\$[\w\[\]{}"']+)/qq($1)/gee;
print $foo, "\n";
}
I would also like to second the suggestion that you take a look at something like Text::Template or HTML::Template; Either of these will allow you to accomplish a similar effect and more. Of course alot depends on what your real goal is.
|