Hi there, i have been testing some code i found in this website and i 've realized it works a bit funny when i change some things on it and i dont understand why. The initial code is this:

use WWW::Mechanize; use HTML::TokeParser; my $webcrawler = WWW::Mechanize->new(); $webcrawler->get("http://www.google.com"); my $content = $webcrawler->content; my $parser = HTML::TokeParser->new(\$content); while($parser->get_tag){ print $parser->get_trimmed_text(),"\n"; }

It gives me the output i want, stripping almost all the HTML from a web page and leaving the contents.Now, if i don't have the webpage specified here and i try to get it with the <STDIN> command when i try to compile and run the program with the perl command then the script gets stuck. It won't even let me type a URL in.

$url_name = <STDIN>; # The user inputs the URL to be searched $webcrawler->get($url_name);

The 3rd version is when the while statement starts i want to save the $parser variable instead of printing it. I tried to save it as an element of an array and a variable on its own.So at the it would change to:

while($parser->get_tag){ my $stripped_html = $parser->get_trimmed_text(),"\n"; #print $parser->get_trimmed_text(),"\n"; print $stripped_html; }
But this gets stuck again for some reason and looking at the proccesses it takes a lot of my CPU power so it probably gets stuck somewhere although i dont know where.This is the same if i initialize an array and use the first element of that array to write the $parser in. Any ideas?Thanks in advance

In reply to Strange way a string or array works 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.