Re: replacing characters in a string
On 18 May 2004 19:12:19 - [EMAIL PROTECTED] (PerlDiscuss - Perl Newsgroups and mailing lists) wrote: I cant find a simple perl function to replace characters in a string. Im trying to inserts strings like bob's into a database and need to convert that to bob''s so that sql doesnt whine when i do an insert. Any suggestions? hi try to use DBI module see perldoc DBI and quote method quote $sql = $dbh-quote($value); $sql = $dbh-quote($value, $data_type); Quote a string literal for use as a literal value in an SQL statement, by escaping any special characters (such as quotation marks) contained within the string and adding the required type of outer quotation marks. $sql = sprintf SELECT foo FROM bar WHERE baz = %s, $dbh-quote(Don't); For most database types, quote would return 'Don''t' (including the outer quotation marks). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- Frédéric Sapet *** Génoplante-Info 523 place des Terrasses 91000 Evry 01 60 87 37 59 [EMAIL PROTECTED] *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: replacing characters in a string
I cant find a simple perl function to replace characters in a string. Im trying to inserts strings like bob's into a database and need to convert that to bob''s so that sql doesnt whine when i do an insert. Any suggestions? There are regex's and the tr/y functions/operators? But in this case you shouldn't use either and instead use binding (assuming you are using DBI, are you?). Binding allows DBI/DBD which is very smart decide how the data needs to be quoted rather than attempting to do this manually which usually just leads to problems. http://search.cpan.org/~timb/DBI-1.42/DBI.pm#Placeholders_and_Bind_Values Alternatively if binding can't be used, there is the 'quote' method for handling this specific task (on same page as above). http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: replacing characters in a string
- Yes I am using DBI. That's perfect, I didnt realize they had this functionality, but it makes alot of sense that they do. Thank you, thank you. Wiggins D Anconia wrote: I cant find a simple perl function to replace characters in a string. Im trying to inserts strings like bob's into a database and need to convert that to bob''s so that sql doesnt whine when i do an insert. Any suggestions? There are regex's and the tr/y functions/operators? But in this case you shouldn't use either and instead use binding (assuming you are using DBI, are you?). Binding allows DBI/DBD which is very smart decide how the data needs to be quoted rather than attempting to do this manually which usually just leads to problems. http://search.cpan.org/~timb/DBI-1.42/DBI.pm#Placeholders_and_Bind_Values Alternatively if binding can't be used, there is the 'quote' method for handling this specific task (on same page as above). http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response