proggybilly
Programmer
I have been working on a script, and have tried searching for what I am looking for but feel i may be asking the wrong question.
I can open a directory, pull a list of files, and open each of those files into an array and display them on my screen.
I need now to input some of the data in the file into a database. I thought I had the right syntax but I am unable to get it to work. My code follows:
I can open a directory, pull a list of files, and open each of those files into an array and display them on my screen.
I need now to input some of the data in the file into a database. I thought I had the right syntax but I am unable to get it to work. My code follows:
Code:
## Populate Database from txt files
$dir = "/u/u/msilog";
opendir(dir, $dir) or die("Cannot open directory");
@files = grep !/^\./, readdir dir;
closedir dir;
foreach my $file(@files){
$path = "$dir/$file";
open(fi, $path);
@file =<fi>;
$myquery = $dbh->do("INSERT INTO backup(server, filename, num_files) values('@file[1]','@file[3]','@file[5]')");
$myquery->execute();
}