PDA

View Full Version : Single Quote replacement!!!


debkumar
08-05-03, 02:05
Hi,

I want to insert a value from a variable into database...
But the value contains a ' (single quote) which cannot be inserted into the database...
I need to escape it with another '.....
Like for eg
variable x="O'Brien" which has to be "O''Brien".
How can i achieve this in perl?????

Thanks in advance...

debkumar
08-05-03, 04:31
$x = O'Brien;
$x =~ s/'/''/g;

WebRecka
08-11-03, 16:42
Its called a regular expression. They are hard to learn but once u got em they are AMAZINGLY HELPFUL. Look up on google for a regx tutorial, there are tons.

debkumar
08-11-03, 22:52
Thanks for the extended help...

Regards
Deb

markguy
08-15-03, 16:46
That works, but a far more robust solution would be to use DBI; and then either pass non-numeric variables through $dbh->quote() or bind the params which will handle escaping for you.