The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
|
#1
|
|||
|
|||
Perl script for csv
I have a number of csv files generated from the admincp->Maint section that I need to push back into a db. These files were generated with the column names, single quote, and comma as the delimiter.
Instead of using myphpadmin to do this one table at a time, I'd just like to write a perl script to loop through the directory contents and call the mysqlimport command passing it the filename. I'm a relative newb to perl syntax so a little review on that would be helpful, but I need to know what values to pass for the mysqlimport switches --fields-optionally-enclosed-by and --fields-escaped-by. Code:
#!/usr/bin/perl -w use strict; my $dir = '/home/DIRNAME/import'; my $dbname = 'MYDBNAME'; my $dbuname = 'DBLOGINNAME'; my $dbpswd = 'DBPASSWORD'; my $importfilename; opendir(DIR, $dir) or die $!; while (my $file = readdir(DIR)) { # No Directories next unless (-f "$dir/$file"); # Look for files ending in .csv next unless ($file =~ m/\.csv$/); # Provide full path to file we want to import $importfilename = "$dir/$file" # Call mysqlimport system('mysqlimport --delete --fields-terminated-by=\',\' --ignore-lines=1 -u $dbuname -p $dbpswd $dbname $importfilename'); } closedir(DIR); exit 0; |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|