Hi monks

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:

5 7 9 . . .
I should take webpages with ID's 5,7,9 and save them in a text file. My code is:
#!/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 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".

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.