lampros21_7 has asked for the wisdom of the Perl Monks concerning the following question:
I have been trying to use Perl to make my life easier again. I must take the webpages from a database for which i have their index. The index numbers are in a text file and they are separated by anew line for each. For example:
I should take webpages with ID's 5,7,9 and save them in a text file. My code is:5 7 9 . . .
The script works fine up to where i print the @webpages array and it comes up fine. The problem is that for some reason the data do not get retrieved from the database and into the @webpages_for_files array so when i print that it gives the warning "Use of uninitialized value".#!/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; open (WEBPAGESFORALL, "<webpages.txt") || die "couldn't open the file +!"; my @webpages = <WEBPAGESFORALL>; close(WEBPAGESFORALL); my $webpage_no = @webpages; my @webpages_for_files; print @webpages; for (my $count=0; $count <= $webpage_no; $count++) { $webpages_for_files[$count] = $db->query("SELECT webpage FROM webpa +ges_data WHERE id = $webpages['$count']'")->list; } print @webpages_for_files; open (WEBPAGES_OUT,">giveit.txt") || die "couldn't open the file!"; foreach my $webp(@webpages_for_files) { print $webp ."\n"; } close(WEBPAGES_OUT);
The thing is i have been using the snippet for the database in another file and it worked fine. Also, for some reason when the numbers in the @webpages array are printed the number in the last element is printed after the many "Use of uninitialized value" warnings. What goes wrong?Thanks for the help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Script won't retrieve data from database
by eric256 (Parson) on Apr 28, 2006 at 19:25 UTC | |
by lampros21_7 (Scribe) on Apr 29, 2006 at 10:39 UTC | |
|
Re: Script won't retrieve data from database
by InfiniteSilence (Curate) on Apr 28, 2006 at 18:55 UTC | |
|
Re: Script won't retrieve data from database
by HollyKing (Pilgrim) on Apr 28, 2006 at 18:29 UTC | |
by kwaping (Priest) on Apr 28, 2006 at 18:32 UTC | |
by lampros21_7 (Scribe) on Apr 28, 2006 at 18:36 UTC | |
|
Re: Script won't retrieve data from database
by ruzam (Curate) on Apr 28, 2006 at 18:31 UTC | |
|
Re: Script won't retrieve data from database
by CountOrlok (Friar) on Apr 28, 2006 at 18:33 UTC |