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:

push @stripped_html, $parser->get_trimmed_text()."\n" while($parser->g +et_tag); print join "", @stripped_html;
Update: provide a solution

Perl is Huffman encoded by design.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.