in reply to How to add quotes to comma separated values in a String
because I'll be passing it to a sql statement as part of an "IN" clause
My first suggestion is to not re-invent the wheel, have a look at SQL::Abstract (example).
DBI provides quote* and quote_identifier, this is the very least you should do - don't go and try to quote the strings yourself.
Also, as an aside, you should always use placeholders wherever possible - see Bobby Tables.
* Update:
use warnings; use strict; use DBI; # just using an SQLite in-memory DB as an example here my $dbh = DBI->connect("dbi:SQLite:dbname=:memory:", '', '', { RaiseError=>1, AutoCommit=>0 } ); my @values = qw/ CAT DOG BIRD COW bl'ah /; my $str = join ',', map { $dbh->quote($_,'VARCHAR') } @values; print $str, "\n"; __END__ 'CAT','DOG','BIRD','COW','bl''ah'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to add quotes to comma separated values in a String (updated)
by Laurent_R (Canon) on Feb 12, 2018 at 23:57 UTC | |
by Your Mother (Archbishop) on Feb 13, 2018 at 01:39 UTC | |
by Laurent_R (Canon) on Feb 13, 2018 at 17:17 UTC | |
by Your Mother (Archbishop) on Feb 13, 2018 at 18:05 UTC | |
by haukex (Archbishop) on Feb 13, 2018 at 21:32 UTC | |
by Laurent_R (Canon) on Feb 13, 2018 at 23:16 UTC | |
| |
|
Re^2: How to add quotes to comma separated values in a String (updated)
by dirtdog (Monk) on Feb 12, 2018 at 22:27 UTC |