When I run a version of your code that prints inside and outside the loop I get the following result (last few lines only):
Inside >Wonderful Web Servers and Bandwidth Generously Provided by < Inside >pair Networks < Inside > < Inside > < Inside > < Inside > < Inside > < Inside > < Outside > <
Do you really mean to overwrite element 0 of the array with each line in succession in the loop so that only the last line is retained?
use warnings; use strict; use WWW::Mechanize; my $webcrawler = WWW::Mechanize->new(); my $uri = URI->new('http://perlmonks.org/?node_id=482163'); $webcrawler->get($uri); my @stripped_html; my $x = 0; my $content = $webcrawler->content; my $parser = HTML::TokeParser->new(\$content); while($parser->get_tag) { $stripped_html[0] = $parser->get_trimmed_text()."\n"; print "Inside >${stripped_html[0]}<\n"; } print "Outside >${stripped_html[0]}<\n";
Probably what you want is to replace the loop and print with this:
Update: provide a solutionpush @stripped_html, $parser->get_trimmed_text()."\n" while($parser->g +et_tag); print join "", @stripped_html;
In reply to Re: My array element won't print outside a loop
by GrandFather
in thread My array element won't print outside a loop
by lampros21_7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |