
BillKSmith
Veteran
Oct 7, 2013, 5:39 AM
Post #2 of 3
(2469 views)
|
Re: [orange] Variable will not stay shared
[In reply to]
|
Can't Post
|
|
I assume that you intend $string to be a lexical variable shared between only these two subroutines. Nesting the subroutine definitions does not do this. Instead, make a new block which contains both subroutines and their shared variables.
{ my $string = ''; sub parseHTML { #... my $p = HTML::Parser->new( start_h => [ \&start, "tag, attr" ], text_h => [ \&text_rtn, 'dtext' ], ); open( my $fh, "<:utf8", $file ) || die; $p->unbroken_text(1); $p->parse_file($fh); #... } sub text_rtn { foreach (@_) { if ( $_ =~ /^(\s*)$/ || $_ =~ /^\W\W\W/ ) { next; } $_ =~ tr/\r\n/ /s; # tr/\000-\040/ /s; $string = $string . $_ . "\n" if $_; } } } Good Luck, Bill
|