Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update mysql within a perl 'for each' loop ?

Status
Not open for further replies.

rab54

Programmer
Jan 28, 2004
112
GB
Hi gurus -

Here is my problem - I am reading in a file,line by line -
I then need to update mysql depending on the 'id' -

eg

foreach $i (@indata) {
chomp($i);

get the fields

#### if I update mysql here, it updates on each iteration - therefore only leaving the last record ###

}

### if I do the update here I only get the first record !

Any help gratefully appreciated !

cheers all

Rab
 
when it comes to perl , I am not great, hence the hack which I use to delete a bunch of stuff:


foreach $cust (@records)
{
$sql = qq {delete from $table where record = '$invalid';\n};
open (MYSQL, "|mysql -h $host -D $db") or die "cannot run mysql command";
print MYSQL "$sql\n";
close MYSQL;
}

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top