I know i have syntax errors and the array @dbfiles it snot filled correctly but at least i tried.my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt"; my @filenames = map {/([^\/]+)\.txt$/} @files; my @dbfiles = $db->do( 'SELECT title, body FROM articles' ); my $replace = $db->prepare( 'INSERT INTO article (title, body) VALUES +(?, ?)' ); foreach $filename (@filenames) { #Check every filename(item in @menu_files) as well as its content t +o see if is already inserted in table articles under columns title an +d body #============ INSERT NEW FILENAMES & CONTENTS INTO DATABASE IF ANY +============= #If filename and content dont already exist in the db then do inser +t them unless( grep /^\Q$filename\E$/, @dbfiles ) { open FILE, "<$filename" or die $!; @data = <FILE>; close FILE; unless( grep /^\Q$data\E$/, @dbfiles ) { $db->do('INSERT INTO articles (title, body) VALUES (?, ?)', u +ndef, $filename, $data) } } }
What i try to do each open each filename and check to see if there is an already column name in the db for that filename, if it is iam also checking for the filenames content to see if it matched the 'body' column of the db
Here is the definition of mysql table articles which is supposes to hold the filenames and their contents.
I believe the logical of the code its correct its the syntax part iam having trouble with.$db->do( 'CREATE TABLE articles (id tinyint auto_increment primary k +ey, title varchar(100), body text)' );
In reply to Re^4: Inserting, update and deleteting a database under conditions
by Nik
in thread Inserting, update and deleteting a database under conditions
by Nik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |