on 07/18/2001 04:11 AM, Scott R. Godin at [EMAIL PROTECTED] wrote:

getting an error now, with HTML::Parser that doesn't happen on the unix box
I also run a similar script on (which I think is running 3.08 but I'll check
in a second ... no it's 3.23 there.)

# Modification of a read-only value attempted.
File 'Primus 8.5GB:Applications:MacPerl Ÿ:site_perl:HTML:Parser.pm'; Line 77


code that generates this error:

#!perl -w

use strict;
use HTML::Parser;

my $infile = 'test.html';

# now we make sure we declare these vars OUTside the loop, (*)
# but before the subs that use them

   my @filedata = ();
   my %inside = ();

sub tag {
    my($tag, $num, $info) = @_;
    $inside{$tag} += $num;
    # not for all tags
    push @filedata, "\n"
        if (($tag eq 'tr') and ($num eq '-1'));
}
sub text {
    return unless $inside{td} || $inside{th};
    chomp(my $txt = $_[0]);
    $txt =~ s/^\s+$//;
    return if $txt eq "";
    push @filedata, "$txt,";
}

# ok let's start by paring down all the unnecessary filesize
# and JUST leave ourselves with the important data
    my $outfile = $infile;
    chop($outfile);
    print "Parsing: $infile into $outfile\n";
    HTML::Parser->new(
       'api_version' => '3',
       'handlers'    => [ 'start' => [ \&tag, "tagname, '+1', attr" ],
                          'end'   => [ \&tag, "tagname, '-1'" ],
                          'text'  => [ \&text, "text" ], ],
       'marked_sections' => '1',
    )->parse_file($infile) || die "Can't open input file: $!\n";

# delete the line
#        'marked_sections' => '1',
# and the problem goes away.
# many of the .t files fail for similar reasons.

    print join("\t", @filedata);

    open OUT, ">$outfile" or die "output file $outfile won't open! : $!" ;
        print OUT @filedata;
    close OUT;



-- 
Scott R. Godin            | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |    web : http://www.webdragon.net/


Reply via email to