This is my script:
#!/usr/bin/perl
use strict;
use warnings;
use Web::Scraper;
use Data::Dumper;
use URI;
my $purlToScrape='http://www.natboard.edu.in/dnbfinal.php';
my $webdata = scraper {
process 'td.noticeboard', "data[]" => 'TEXT';
};
my $dnbnotices = $webdata->scrape(URI->new($purlToScrape));
my @noticeboard=$dnbnotices->{data};
print ref @noticeboard."\n\n";
print Dumper(@noticeboard);
print scalar @noticeboard."\n";
for my $notice ( @noticeboard ) {
if ($notice) {
print $notice."\n";
}
}
print $noticeboard[1];
Output:
$VAR1 = [
'December - 2016 ',
'DNB Final December -2016',
'30th September, 2016',
'',
'',
'JUNE - 2016 ',
'DNB Final JUNE -2016',
'15th May, 2016',
'',
'',
'Dec - 2015 ',
'DNB Final Dec -2015',
'9th October, 2015',
'',
'',
'June - 2015 ',
'DNB Final June -2015',
'6th May, 2015',
'',
'',
'December - 2014 ',
'DNB Final December - 2014',
'30th September, 2014',
'',
''
];
1
ARRAY(0x4521bd8)
Use of uninitialized value in print at ./test1.pl line 21.
Questions:
- Why is the ref not printing out "ARRAY"?
- Why is the array count shown as 1? It's not a single element array.
- Why are the elements of the array not being printed out?
- Why is
$noticeboard[1]uninitialized?
Dumper(\%hash)orDumper(\@array). It's too confusing otherwise, as you've found out (since your array truly does have only one element, a reference to another array).