Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Inserting, update and deleteting a database under conditions

by Nik
on Jan 09, 2008 at 12:51 UTC ( #661340=note: print w/ replies, xml ) Need Help??


in reply to Re: Inserting, update and deleteting a database under conditions
in thread Inserting, update and deleteting a database under conditions

well i didn't go far and the code apart form logical errors has syntax errors as well, its a total mess.


Comment on Re^2: Inserting, update and deleteting a database under conditions
Re^3: Inserting, update and deleteting a database under conditions
by apl (Monsignor) on Jan 09, 2008 at 14:28 UTC
    Most of the Monks, myself included, will be more than happy to help you, but I doubt any of us will write the entire program for you.

    If you give us the syntax errors, we can help you resolve those. If you show us the database code, and tell us what the logical errors were, we can point you in the proper direction. Otherwise, ...
      Okey here is the code for the 1st of 3 parts of my question thati wrote:
      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) } } }
      I know i have syntax errors and the array @dbfiles it snot filled correctly but at least i tried.

      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.

      $db->do( 'CREATE TABLE articles (id tinyint auto_increment primary k +ey, title varchar(100), body text)' );
      I believe the logical of the code its correct its the syntax part iam having trouble with.
        With use strict; you get the following errors:

        Global symbol "$db" requires explicit package name at /apps/otctest/bi +n/report/xx.perl line 8. Global symbol "$filename" requires explicit package name at /apps/otct +est/bin/report/xx.perl line 11. Global symbol "@data" requires explicit package name at /apps/otctest/ +bin/report/xx.perl line 21. Variable "$data" is not imported at /apps/otctest/bin/report/xx.perl l +ine 24. Global symbol "$data" requires explicit package name at /apps/otctest/ +bin/report/xx.perl line 24. Variable "$data" is not imported at /apps/otctest/bin/report/xx.perl l +ine 26. Global symbol "$data" requires explicit package name at /apps/otctest/ +bin/report/xx.perl line 26.
        The simple fix is

        foreach my $filename (@filenames) {

        I'm not trying to be snarky; what do you think $db and @data are? (The errors are telling you to define them.) Once you do, revised: you're going to start getting errors due to the underlying logical problems in your code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://661340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2014-07-26 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls