in reply to Using GET in a loop

use LWP::Simple; foreach $ID (@ID) { $content=" "; $url="http:://...docid=$ID"; # this is completely NEW value $content=get($url); # here you APPEND new value to the previous values open FILE, ">> C:/perl/output.txt"; print FILE $content; }

Replies are listed 'Best First'.
Re^2: Using GET in a loop
by New Novice (Sexton) on Sep 17, 2004 at 09:30 UTC
    This is exactly what I expected to happen, but it doesn't.

    Each time the (global or local) variable $content gets a new value assigned (via GET), the content of the variable is not replaced by the new value (content of the newly retrieved website) but it is appended.

    This is the case even when I explicitly "empty" it ($content= " "). Apparently, GET uses an internal variable to store the information retrieved, which is appended. Thus, each time the loop is executed $content simply gets bigger and bigger as this internal variable adds the content of newly retrieved webpages to all previously retrieved ones.

    Thank you for your response!