in reply to Script won't retrieve data from database

You have a couple of issues that once fixed will probably help you find the problem (or fix the problem. You arn't chomping the lines so you will have '5\n' instead of just '5' which is probably messing up the query. You are also using a C style loop instead of more perlish way that will require less variables ;) So here is your code with some minor changes that shouldn't break anything:

#!/usr/bin/perl use warnings; use strict; use DBIx::Simple; my $db = DBIx::Simple->connect('dbi:SQLite:dbname=mydatabase.db') or die DBIx::Simple->error; #switch to 3 arg form, no advantage here but its a good habit ;) open (WEBPAGESFORALL, "<", "webpages.txt") || die "couldn't open the f +ile!"; my @webpages = <WEBPAGESFORALL>; close(WEBPAGESFORALL); #remove trailing newlines chomp(@webpages); my @webpages_for_files; #print out the id's of the pages we want, seperated by commas print join(",", @webpages); #loop over the indexs we just grabbed from the file for (@webpages) { #push this page onto our list of saved pages. push @webpages_for_files, $db->query("SELECT webpage FROM webpages_d +ata WHERE id = ?", $_)->list; #change the query to use place holders } print join(",", @webpages_for_files); #three arg form open (WEBPAGES_OUT,">", "giveit.txt") || die "couldn't open the file!" +; foreach my $webp (@webpages_for_files) { print $webp ."\n"; } close(WEBPAGES_OUT);

___________
Eric Hodges

Replies are listed 'Best First'.
Re^2: Script won't retrieve data from database
by lampros21_7 (Scribe) on Apr 29, 2006 at 10:39 UTC
    Thanks to everyone for the replies. I have found that the problem is the missing chomp command  chomp(@webpages); but its good to see more effective ways of doing things as well. Thanks