M
Mike Solomon
I have written the following script to replaces items in a line that
are enclosed with braces with variables of the same name
use strict;
my $test = 'mike test {VAR1} hhhh {VAR2}';
my %vars = (VAR1 => 'mike1', VAR2 => 'mike2');
while ($test =~ /{/) {
$test =~ /({.*?})/;
my $new = $1;
$new =~ s/{|}//g;
$test =~ s/{.*?}/$vars{$new}/;
}
print "$test\n";
I am sure there is a better way of writing this and would appreciate
your comments
Thanks
Mike
are enclosed with braces with variables of the same name
use strict;
my $test = 'mike test {VAR1} hhhh {VAR2}';
my %vars = (VAR1 => 'mike1', VAR2 => 'mike2');
while ($test =~ /{/) {
$test =~ /({.*?})/;
my $new = $1;
$new =~ s/{|}//g;
$test =~ s/{.*?}/$vars{$new}/;
}
print "$test\n";
I am sure there is a better way of writing this and would appreciate
your comments
Thanks
Mike