G
Geoff Cox
Hello
Several hours of trying and I cannot see what is wrong with the code
below ... I am new to OOP so may have got some of that wrong?
The sub classroomnotes slurp is not finding the $curr, $next1, $next2,
$next3 values. I get error messages re "use of uninitialized value in
pattern match"
The basic idea is that a series of html files in the oldshort2 folder
is parsed and when an option value is found, the intro text is found
from the total-160404.txt file and the links to the full documents are
found from the allphp2.php file. These links are not being found.
Any ideas please?
Thanks
Geoff
package MyParser;
use base qw(HTML:arser);
use File::Find;
my $in_heading;
my $p;
my $dir = ("d:/a-keep9/short-nondb/oldshort2");
find sub {
my $name = $_;
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name");
print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");
sub start {
my ($self, $tagname, $attr, undef, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 1;
return;
}
if ($tagname eq 'p') {
$p = 1;
return;
}
if ($tagname eq 'option') {
choice($attr->{ value });
}
}
sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}
if ($tagname eq 'p') {
$p = 0;
return;
}
}
sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;
}
sub choice {
my ($path) = @_;
if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}
}
sub intro {
my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt");
my $lineintro;
while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}
sub classroomnotes {
my ($pattern) = @_;
open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php");
my $line = <INNN>;
while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);
if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
"Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}
}
print OUT ("</body></html> \n");
package main;
open (IN, $name);
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);
}, $dir;
Several hours of trying and I cannot see what is wrong with the code
below ... I am new to OOP so may have got some of that wrong?
The sub classroomnotes slurp is not finding the $curr, $next1, $next2,
$next3 values. I get error messages re "use of uninitialized value in
pattern match"
The basic idea is that a series of html files in the oldshort2 folder
is parsed and when an option value is found, the intro text is found
from the total-160404.txt file and the links to the full documents are
found from the allphp2.php file. These links are not being found.
Any ideas please?
Thanks
Geoff
package MyParser;
use base qw(HTML:arser);
use File::Find;
my $in_heading;
my $p;
my $dir = ("d:/a-keep9/short-nondb/oldshort2");
find sub {
my $name = $_;
open (OUT, ">>d:/a-keep9/short-nondb/short/members2/$name");
print OUT ("<html><head><title>test</title></head><body> \n");
print OUT ("<table width='100%' border='1'> \n");
sub start {
my ($self, $tagname, $attr, undef, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 1;
return;
}
if ($tagname eq 'p') {
$p = 1;
return;
}
if ($tagname eq 'option') {
choice($attr->{ value });
}
}
sub end {
my ($self, $tagname, $origtext) = @_;
if ($tagname eq 'h2') {
$in_heading = 0;
return;
}
if ($tagname eq 'p') {
$p = 0;
return;
}
}
sub text {
my ($self, $origtext) = @_;
print OUT ("<h2>$origtext</h2> \n") if $in_heading;
print OUT ("<p>$origtext</p> \n") if $p;
}
sub choice {
my ($path) = @_;
if ($path =~ /docs\/aslevel\/classroom-notes/) {
intro($path);
classroomnotes($path);
}
}
sub intro {
my ($pathhere) = @_;
open (INN, "d:/a-keep9/short-nondb/db/total-160404.txt");
my $lineintro;
while (defined ($lineintro = <INN>)) {
if ($lineintro =~ /$pathhere','(.*?)'\)\;/) {
print OUT ("<tr><td>$1 <p> </td>\n");
}
}
}
sub classroomnotes {
my ($pattern) = @_;
open (INNN, "d:/a-keep9/short-nondb/allphp/allphp2.php");
my $line = <INNN>;
while (<INNN>){
last if /$pattern/;
}
my ($curr, $next1, $next2, $next3) = <INNN>;
close (INNN);
if ($next3 =~ /\$i\<(\d+);/) {
my $nn = $1;
print OUT ("<td valign='top'> \n");
for ($c=1;$c<$nn;$c++) {
print OUT ('<a href="'. $pattern . "-doc" . $c . ".zip" . '">' .
"Document$c" . "</a><br>" . "\n");
}
print OUT ("</td></tr>\n");
}
}
print OUT ("</body></html> \n");
package main;
open (IN, $name);
undef $/;
my $html = <IN>;
my $parser = MyParser->new;
$parser->parse($html);
}, $dir;