Hi, I saw the doc for HTML::Parser. I looked at its hstrip program in the eg folder but dunno how to strip a scalar instead of a file. I can strip a file. But I want to strip a scalar. Any help appreciated.
As my code is currently, when ran, it prints text to STDOUT and the $source scalar variable holds html I do not need to print to STDOUT Is the print @ line in the sub doing this? I need to strip the html from $source What am I doing wrong whereby the html does not get stripped from $source ? -- So that I can then uncomment my __END__ So that the latter part of my program will then run. The latter part of my program works correctly; it finds a unique text string then prints it along with a specified number of subsequent lines. (This is what I want) but in order for this latter part to work, the html needs to be stripped from $source Current code is next: #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $url = ' http://www.wrh.noaa.gov/total_forecast/getprod.php?wfo=sto&sid=STO&pil=ZFP'; # my $url = 'http://www.slackware.com/changelog/current.php?cpu=i386'; my $response = $ua->get( $url ); $response->is_success or $response->code == 404 # ignore 404 or die "Can't get '$url': ", $response->status_line; # print $response->content; # __END__ my $source = $response->content; $source =~ s/\n+/\n/g; # Strip html markup #################### use HTML::Parser (); sub text_handler { # Ordinary text print @_; } my $p = HTML::Parser->new(api_version => 3); $p->handler( text => \&text_handler, "dtext"); $p->parse($source); $p->eof; print "~source~\n"; print $source; __END__ # print $source; my @raw = split(/\n/, $source); # print scalar( @raw ); my $line; my $stop_at; foreach ( @raw ) { $line++; if ( /CAZ017/ ) { $stop_at = $line + 40; } next unless $stop_at; print $_, "\n" if $line <= $stop_at; } # end ------------------------------------------------------ Ultimately, I want to print the CA (California) zone 17 forecast (southern Sacramento valley forecast). Probably will knock that $line + 40 down to $line + 15 or thereabouts. But, I need to strip the html from $source first. Thanks. -- Alan.