G
Geoff Cox
Keith,
I am trying to implement your ideas but part is OK and part not ...
I am able to use
: main::choice( $attr->{value});
to pass the option data to the sub choice, but not clear how to get
the $text printed to OUT etc (ie into the results.htm file).
Also, not clear how to stop the data being printed to the screen? This
will tell you that I am not at all clear re how your code works!! eg
have I structured the code correctly? Would really appreciate it if
you could give brief explanation.
Cheers
Geoff
use strict;
use warnings;
use HTML:arser;
my $data;
open (IN, "test.htm");
{ local $/; $data = <IN> }
my @to_print = qw[h2 p];
my @get_attr = qw[option];
my $current_tag = '';
sub start_tag {
my ($tag, $attr, $text) = @_;
$current_tag = $tag;
( grep { $current_tag eq $_ } @to_print )
? print $text
# ? main:rinttext($text)
# : print $attr->{value};
: main::choice( $attr->{value});
}
sub default {
print shift if grep { $current_tag eq $_ } @to_print;
}
package main;
open( OUT, ">>results.htm" )
|| die "results.htm: $!"; #
print OUT ("<table width='100%' border='1'><tr> \n");
my $parser = HTML:arser->new
(
report_tags => [ @to_print, @get_attr ],
default_h => [ \&default, 'text' ],
start_h => [ \&start_tag, 'tagname, attr, text' ],
)->parse( $data ) or die $!;
sub printtext {
my $text = @_ ;
print OUT ("<p> $text </p> \n");
}
sub choice {
my ($path) = @_;
if ( $path =~ /docs\/gcse\/student-activities\/finance/ ) {
intro($path);
gcsestudentactivitiesfinance($path);
} elsif ( $path =~ /docs\/gcse\/student-activities\/marketing/ ) {
intro($path);
gcsestudentactivitiesmarketing($path);
}
}
I am trying to implement your ideas but part is OK and part not ...
I am able to use
: main::choice( $attr->{value});
to pass the option data to the sub choice, but not clear how to get
the $text printed to OUT etc (ie into the results.htm file).
Also, not clear how to stop the data being printed to the screen? This
will tell you that I am not at all clear re how your code works!! eg
have I structured the code correctly? Would really appreciate it if
you could give brief explanation.
Cheers
Geoff
use strict;
use warnings;
use HTML:arser;
my $data;
open (IN, "test.htm");
{ local $/; $data = <IN> }
my @to_print = qw[h2 p];
my @get_attr = qw[option];
my $current_tag = '';
sub start_tag {
my ($tag, $attr, $text) = @_;
$current_tag = $tag;
( grep { $current_tag eq $_ } @to_print )
? print $text
# ? main:rinttext($text)
# : print $attr->{value};
: main::choice( $attr->{value});
}
sub default {
print shift if grep { $current_tag eq $_ } @to_print;
}
package main;
open( OUT, ">>results.htm" )
|| die "results.htm: $!"; #
print OUT ("<table width='100%' border='1'><tr> \n");
my $parser = HTML:arser->new
(
report_tags => [ @to_print, @get_attr ],
default_h => [ \&default, 'text' ],
start_h => [ \&start_tag, 'tagname, attr, text' ],
)->parse( $data ) or die $!;
sub printtext {
my $text = @_ ;
print OUT ("<p> $text </p> \n");
}
sub choice {
my ($path) = @_;
if ( $path =~ /docs\/gcse\/student-activities\/finance/ ) {
intro($path);
gcsestudentactivitiesfinance($path);
} elsif ( $path =~ /docs\/gcse\/student-activities\/marketing/ ) {
intro($path);
gcsestudentactivitiesmarketing($path);
}
}