my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt"; my @menu_files = map m{([^/]+)\.txt}, @files; my @dbfiles = $db->do( 'SELECT title, body FROM articles' ); my $replace = $db->prepare( 'INSERT INTO article (title, body) VALUES +(?, ?)' ); foreach ( @menu_files ) { #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 don't already exist in the db then do inse +rt them #===== UPDATE THE DB ENTRY IF THERE IS A MODIFICATION IN A FILES C +ONTENTS ===== #If filename exists in the db under column title but its content is + different from the database's content then update column body in the + db #======== DELETE ANY DB ENTRY OF A FILENAME THATDOESNT EXIST ANY M +ORE ========= #Delete all db records that doesnt have a corresponding filename in + the hdd }
In reply to Inserting, update and deleteting a database under conditions by Nik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |