search and replace a SQL query
- From: goldenplec@xxxxxxxxx
- Date: 29 Dec 2005 09:07:26 -0800
i have a sql query in a variable called $sql
i want to search through the query and for every placeholder insert a
variable
Example
$sql = select * from table where user = ? id = ? address = ? name = ?
and i want to replace the question marks with a variable to complete
the query
so ive tried
$sql =~ s/"?"/$user/;
$sql =~ s/"?"/$id/;
$sql =~ s/"?"/$address/;
$sql =~ s/"?"/$name/;
which i thought would go in to $sql the first time, find the first ?
and put the contents on $user in place of the ? then the second time
there would only be 3 question marks left so the second line of code
should replace the second question mark with the content of the next
variable.
could anybody push me in the right direction here. its starting to
drive me nuts
.
- Follow-Ups:
- Re: search and replace a SQL query
- From: usenet
- Re: search and replace a SQL query
- Prev by Date: Re: getting a time diff from strings
- Next by Date: RE: strange problem with STDIN- need help
- Previous by thread: Installing Perl
- Next by thread: Re: search and replace a SQL query
- Index(es):
Relevant Pages
|