Rahul Gupta has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to substitute values in query but things are not working for me.
Here is my code
my @array_1 = ("\$Id_run_query=1", "\$name_run_query=xyz", "db_query_r +un_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";
the expected output is :
"select * from meter where metetid=1 and metername=xyz"but i am geeting this:
"select * from meter where metetid=$Id and metername=$name"Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex is not working
by moritz (Cardinal) on Oct 03, 2013 at 05:21 UTC | |
by Rahul Gupta (Sexton) on Oct 03, 2013 at 05:28 UTC | |
|
Re: Regex is not working
by CountZero (Bishop) on Oct 03, 2013 at 16:06 UTC | |
|
Re: Regex is not working
by kcott (Archbishop) on Oct 03, 2013 at 06:18 UTC |