http://qs1969.pair.com?node_id=898705

parkprimus has asked for the wisdom of the Perl Monks concerning the following question:

I am creating a scrapper that gets the url from an index and writes it to a dat file. Then another scrapper that reads the dat in a while loop and scrapes data from it. I have two different version of code one that works and one that doesn't. The one that works, I have defined the content in which to scrape. The one that doesn't work, the content is defined in a variable which is read from the dat file. If anyone can help, it would be much appretiated.
Works:
#!/usr/bin/perl use LWP::Simple; use HTML::TokeParser; use URI::Escape; &sw; sub sw { $content = get('http://example.com/test.html'); ....truncated
Doesn't work:
#!/usr/bin/perl -w use LWP::Simple; use HTML::TokeParser; use URI::Escape; use DBI; use DBD::mysql; $database = "Assets2"; $host = "localhost"; $port = "3306"; $user= "assets"; $password= "xxx"; $dsn = "DBI:mysql:$database:$host:$port"; $connect = DBI->connect($dsn,$user, $password); &get_index; sub get_index { $query1 = "Select * from devices"; $query_handle1 = $connect->prepare($query1); $query_handle1->execute; $query_handle1->bind_columns(\$id,\$device); while ($query_handle1->fetch) { print "id: $id\tname: $device\n"; &switch_properties; } } sub switch_properties { $content = get('http://example.com/$device'); ...truncated
Error:
Use of uninitialized value in substr at /usr/lib/perl5/HTML/PullParser +.pm line 80. Use of uninitialized value in length at /usr/lib/perl5/HTML/PullParser +.pm line 83.
Error with debugger:
Use of uninitialized value in substr at /usr/lib/perl5/HTML/PullParser +.pm line 80. at /usr/lib/perl5/HTML/PullParser.pm line 80 HTML::PullParser::get_token('HTML::TokeParser=HASH(0x9ce9fd0)' +) called at /usr/lib/perl5/HTML/TokeParser.pm line 52 HTML::TokeParser::get_tag('HTML::TokeParser=HASH(0x9ce9fd0)', +'tr') called at switchmapHTMLTEST1.pl line 51 main::switch_properties called at switchmapHTMLTEST1.pl line 2 +8 main::get_index called at switchmapHTMLTEST1.pl line 19 Use of uninitialized value in length at /usr/lib/perl5/HTML/PullParser +.pm line 83. at /usr/lib/perl5/HTML/PullParser.pm line 83 HTML::PullParser::get_token('HTML::TokeParser=HASH(0x9ce9fd0)' +) called at /usr/lib/perl5/HTML/TokeParser.pm line 52 HTML::TokeParser::get_tag('HTML::TokeParser=HASH(0x9ce9fd0)', +'tr') called at switchmapHTMLTEST1.pl line 51 main::switch_properties called at switchmapHTMLTEST1.pl line 2 +8 main::get_index called at switchmapHTMLTEST1.pl line 19