On Mon, 2005-07-18 at 11:53, Wiggins d'Anconia wrote:

I had to add a 'chomp' and make sure the line endings in my file were
correct, but this worked and I learned something useful as well.

Thank you.  :-)

--charlie

> Only do things in the loop that must be done in the loop. Reconnecting,
> repreparing, and disconnecting from the DB is a lot of unnecessary work.
> 
> perldoc DBI
> 
> 
> --Untested--
> #!/usr/bin/perl -w
> 
> use strict;
> use DBI;
> use DBD::Pg;
> 
> my $infile = $ARGV[0];
> 
> # no reason to reconnect for every line
> my $dbh = DBI->connect("dbi:Pg:dbname=*, "*", "*") || die;
> 
> # statement should only be prepared once
> # note use of placeholder ? character
> my $sth = $dbh->prepare("UPDATE table SET email = '' WHERE email = ? ")
> || die;
> 
> open INFILE, "<$infile" or die "Can't open file for reading: $!";
> while ( <INFILE> ) {
>    $sth->execute( $_ );
> }
> close INFILE;
> 
> $sth->finish;
> $dbh->disconnect;
-- 
Charles Farinella 
Appropriate Solutions, Inc. (www.AppropriateSolutions.com)
[EMAIL PROTECTED]
603.924.6079


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to