Lawrence Statton wrote: >>On Mon, 2005-07-18 at 11:53, Wiggins d'Anconia wrote: >> >>>Charles Farinella wrote: >>> >>>>I'm sure this is very simple and I am overlooking something. I want to >>>>read a list of bad email addresses from a file and remove them from my >>>>database. >>>> >>>>If I print $_, the email addresses are correct, if I try to remove them >>>>from the db I get errors on just the characters before the @. >>>> >>> >>>Are you sure those errors aren't coming from the DB? > > > Use placeholder constants. Like this > > ------------- cut here ------------------------------------- > #!/usr/bin/perl > use strict; > use warnings; > use Data::Dumper; > > use DBI; > > our $DBH = DBI->connect( 'dbi:Pg:dbname=test', undef , undef ); > > die "no database" unless $DBH; > > while (<DATA>) > { > chomp; > $DBH->do( qq { > DELETE FROM email > WHERE address = ? > } , {} , $_ ) or print $DBH->errstr; > } >
Careful with such advice, switching a statement from an update where you set an empty string is *significantly* different than switching to a delete. I even resisted the urge to switch the setting to '' to a NULL as that technically may not fit with his data model. Obviously from my other posts I agree about using placeholders, though I don't agree with using a 'do' in a loop. TMTOWTDI. http://danconia.org > __DATA__ > Evil Spacey [EMAIL PROTECTED] > ------------- cut here ------------------------------------- > > > If you absolutely refuse to do this (and be prepared to suffer a life > of SQL injection if you do so refuse) then at LEAST call $dbh->quote() > on strings before you hand them off to DBI. > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>