I want to retrieve information from a number of pages that all have the same structure. Thus, I would like to use a retrieve them via GET and process their information in a loop. However, GET seems to store the information in a hidden variable and appends it. Instead of replacing the content of my "temporary" variable the content of the new website is appended to the content of all previously retrieved ones. Thus, my information processing (getting various information from the "temporary" content variable and assigning it to other variables) always yields the same results, the one from the first website retrieved. Because I rely on the structure of the website to identify the necessary bits and pieces of information, I need the content variable to be replaced everytime.

I already tried global and local variables. Furthermore, I "empty" the content variable every time prior to retrieving a new site. None of this works.

Here is the (abbreviated) code:

use LWP::Simple; foreach $ID (@ID) { $content=" "; $url="http:://...docid=$ID"; $content=get($url); # subsequently I extract information from the string # $content, which only serves as a contemporary storage Open FILE, ">> C:/perl/output.txt"; Print FILE $content; # actually it's all the other variables whose values I # want to save }

In reply to Using GET in a loop by New Novice

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.