perlquestion
Rahul Gupta
Hi,
<p>I am trying to substitute values in query but things are not working for me. </p>
<p>Here is my code</p>
<code>
my @array_1 = ("\$Id_run_query=1", "\$name_run_query=xyz", "db_query_run_query=select * from meter where metetid=\$Id and metername=\$name");
my $query;
foreach(@array_1){
if ($_ =~ m/^db_query_run_query=(.*)/i){$query = $1;print "$1\n";}
}
foreach(@array_1){
if ($_ =~ m/^(\$\S+)=(.*)/i){
my $replace = $2;
my $value = shift @{ [ split( /_/, $_ ) ] };
print "$value\n";
chomp($value);
# print "$query\n";
$query =~ s/$value/$replace/i;
}
}
print "===>$query\n";
</code>
<p>the expected output is :</p><code>"select * from meter where metetid=1 and metername=xyz"</code><p> but i am geeting this:</p> <code>"select * from meter where metetid=$Id and metername=$name"</code>
<p> Thanks in advance</p>