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

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.

Replies are listed 'Best First'.
Re^6: Inserting, update and deleteting a database under conditions
by Nik (Initiate) on Jan 15, 2008 at 16:00 UTC
    Well i frgoto 'my'. Except that when iam trying to print @dbfiles it display to me the numder 28, so i guess my statement concernign @dbfiles is also wrong. I was trying to get the data from columns title and body.

    how can i write that properly and what logical error do you see?

      How does $db get initialized? When you do the INSERT, what values should be in place of the question marks you specified?
        Like this:
        #===================================================================== +========== my $db = ( $ENV{'SERVER_NAME'} !~ /varsa/ ) ? DBI->connect('DBI:mysql:orthodox;localhost', 'root', '******' +, {RaiseError=>1}) : DBI->connect('DBI:mysql:skieros_orthodox;www.freegreece.net', + 'skieros_root', '******', {RaiseError=>1}); #===================================================================== +========== my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt"; my @filenames = map {/([^\/]+)\.txt$/} @files; my @dbfiles = $db->do( 'SELECT title, body FROM articles' ); foreach my $filename (@filenames) { unless( grep /^\Q$filename\E$/, @dbfiles ) { open FILE, "<$filename" or die "Cannot open $filename: $!"; my $data = <FILE>; close FILE; unless( grep /^\Q$data\E$/, @dbfiles ) { $db->do('INSERT INTO test (title, body) VALUES (?, ?)', undef +, $filename, $data) } } }
        The content of @dbfiles isnt what i think it is though. What i wanted to return is all table's articles contents.