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 to see if is already inserted in table articles under columns title and body #============ INSERT NEW FILENAMES & CONTENTS INTO DATABASE IF ANY ============= #If filename and content don't already exist in the db then do insert them #===== UPDATE THE DB ENTRY IF THERE IS A MODIFICATION IN A FILES CONTENTS ===== #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 MORE ========= #Delete all db records that doesnt have a corresponding filename in the hdd }