I am writing a little script to change my flat file database of members to mysql. The problem I am having is because each member has it's own text file (All in one folder), I can't get it to read all the files and transfer all of them, I can get it to transfer individual files though. I am trying to use grep to get all the file names. And that works if I print it on the page but not when I try to open them... I have for the code:
#!/usr/bin/perl
use CGI qw(:standard);
print "Content-type: text/html\n\n";
require "shopconfig.cgi";
use DBI();
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=crashint_test;host=localhost",
"crashint", "PASSWORD",
{'RaiseError' => 1});
my @count = ();
opendir (DR,"$datapath/members/");
@count = grep { /\..*/ } readdir(DR);
closedir (DR);
foreach $line (sort @count) {
print "$line<br>";
open(LIST, "<$datapath/members/$line");
while(<LIST>) {
my ($Username, $Password, $lname, $fname, $country, $email, $add1, $add2, $city, $state, $zip, $phone) = split/\|/;
$dbh->do("INSERT INTO foo VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef, "$Username", "$Password", "$fname", "$lname", "$country", "$email", "$add1", "$add2", "$city", "$state", "$zip", "$phone");
}
close(LIST);
}
# Disconnect from the database.
$dbh->disconnect();
Thanks in advance..
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central
Code:
#!/usr/bin/perl
use CGI qw(:standard);
print "Content-type: text/html\n\n";
require "shopconfig.cgi";
use DBI();
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=crashint_test;host=localhost",
"crashint", "PASSWORD",
{'RaiseError' => 1});
my @count = ();
opendir (DR,"$datapath/members/");
@count = grep { /\..*/ } readdir(DR);
closedir (DR);
foreach $line (sort @count) {
print "$line<br>";
open(LIST, "<$datapath/members/$line");
while(<LIST>) {
my ($Username, $Password, $lname, $fname, $country, $email, $add1, $add2, $city, $state, $zip, $phone) = split/\|/;
$dbh->do("INSERT INTO foo VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef, "$Username", "$Password", "$fname", "$lname", "$country", "$email", "$add1", "$add2", "$city", "$state", "$zip", "$phone");
}
close(LIST);
}
# Disconnect from the database.
$dbh->disconnect();
Thanks in advance..
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central