K
Krishna Komoravolu
Hello!
Pardon me for this trivial question.
Is there a way to expand a perl variable with in a variable?
i.e. when I read a line "$line" from an input file,
say the line in text(xml) file is like:
$t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
when I print this line with print "$line", I want the variables $t and
$c in the above line to be expanded in the output.
In the code segment given below, the last case of the switch i.e.
print "$line" literally prints $t and $c with out expanding them.
while (<IFH>) {
my $line = $_;
SWITCH: for ($line) {
/<TableDef[ ]*name/i &&
do {$line =~ /(")(\w+)/; $t = $2; last;}; # set $t
/<ColumnDef[ ]*name/i &&
do {$line =~ /(")(\w+)/; $c = $2; last;}; # set $c
/<RuleDef/i &&
do {$line =~ /(")(\w+)/; $rule = 1; last;}; # set rule
/<\/RuleDef/i &&
do {$line =~ /(")(\w+)/; $rule = 0; last;}; # unset rule
/[aA-zZ]+/ &&
do {print "$line" if $rule == 1; last;};
}
}
Thanks in advance for any help!
Kris
Pardon me for this trivial question.
Is there a way to expand a perl variable with in a variable?
i.e. when I read a line "$line" from an input file,
say the line in text(xml) file is like:
$t:references([@CONTROLLER_TYPE = 0]/@$c) in ....,
when I print this line with print "$line", I want the variables $t and
$c in the above line to be expanded in the output.
In the code segment given below, the last case of the switch i.e.
print "$line" literally prints $t and $c with out expanding them.
while (<IFH>) {
my $line = $_;
SWITCH: for ($line) {
/<TableDef[ ]*name/i &&
do {$line =~ /(")(\w+)/; $t = $2; last;}; # set $t
/<ColumnDef[ ]*name/i &&
do {$line =~ /(")(\w+)/; $c = $2; last;}; # set $c
/<RuleDef/i &&
do {$line =~ /(")(\w+)/; $rule = 1; last;}; # set rule
/<\/RuleDef/i &&
do {$line =~ /(")(\w+)/; $rule = 0; last;}; # unset rule
/[aA-zZ]+/ &&
do {print "$line" if $rule == 1; last;};
}
}
Thanks in advance for any help!
Kris