#!/usr/bin/perl

use HTML::Parser ();
my $msg;
my $definp = "C:/Documents and Settings/Geoff McLane.PRO-1/My Documents/My Webs/moon-01.htm";

$msg = "Begin processing ...\n";
print $msg;

my $pp = HTML::Parser->new( api_version => 3,
						### start_h => [\&my_start, "tagname, attr"],
						start_h => [\&my_start2, "self,tokens" ],
                        end_h   => [\&my_end,   "tagname"],
						text_h  => [\&my_text,  "text"],
                        marked_sections => 1,
                       );

print "Begin parse of $definp ...\n";
$pp->parse_file($definp);
print "End parse of $definp ...\n";

sub my_start2 {
	my ($self, @toks) = @_;
	$msg = '';
	foreach my $tkn (@toks) {
		$msg .= " $tkn"
	}
	print "@toks\n";
	print "$msg \n";
}

sub my_start {
	my ($tg,%atr) = @_;
	my @attr = %atr;
	#$msg = "Start=[$tg] Attr=[";
	#$msg .= join (" ", @attr);
	#$msg .= "]\n";
	#print $msg;
	print "size of hash:  " . keys( %atr ) . ".\n";
	$msg = "Start=[$tg] Attr=[";
    while ( my ($key, $value) = each(%atr) ) {
        $msg .= " $key => $value";
    }
	$msg .= "]\n";
	print $msg;

	$msg = "Start=[$tg] Attr=[";
	for my $key2 ( keys %atr ) {
        my $value2 = $atr{$key2};
        $msg .= " $key2 => $value2";
    }
	$msg .= "]\n";
	print $msg;
}

sub my_end {
	my ($tge) = @_;
	$msg = "End=[$tge]\n";
	#print $msg;
}

sub my_text {
	my ($txt) = @_;
	## chomp $txt;
    ## print "text=[$txt]\n";
	## print $txt;
}

sub my_comm {
	my ($txt) = @_;
	## chomp $txt;
    ## print "text=[$txt]\n";
	print $txt;
}
