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
In reply to Script won't retrieve data from database by lampros21_7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |