1

I have a MYSQL DB and I need to do some text manipulation on one of the fields. This is a one-off, not an ongoing process.

The built in MySQL text manipulation functions will be a nightmare to do what I need to do. Perl can do it in a few lines, and I even have a perl script hanging aorund with the exact text manipulation commands needed.

Dumping the table to a text file, Perling it, and then restoring it would work but is a bit cumbersome; is there an easier or better way to use perl to manipulate the data within the mysql DB to cycle through each row in the table, edit the data in a field, and move on the the next row?

2 Answers 2

2

The best method would be to modify the data "in place" using Perl's MySQL DBI.

SELECT the data, perform the regex and send it back with an UPDATE.

My personal preference would be to use Python, with it's MySQLdb and re modules.

1

You can use the DBI module with the DBD::mysql driver to access the database for reading and writing, and just loop through the rows you're interested in. The documentation should be enough to give you a decent start, but it could be a good idea to back things up before you break stuff.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .