Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: How to Properly Clear Variables for reuse in a loop

by linuxer (Curate)
on Apr 23, 2009 at 22:12 UTC ( #759684=note: print w/replies, xml ) Need Help??

in reply to How to Properly Clear Variables for reuse in a loop

Your variables are declared with my within the while loop. So they are re-initialized on each run and shouldn't know of their previous value.

And you assign a value to $url on each run; so it should even work without the my inside the loop, as the content of $url is overwritten on each run of the loop.

Ergo: If you see the same output per run, the problem is in FetchURL as others already mentioned.

$ perl -wle ' > my $i = 1; > while ( $i < 5 ) { > my $j = $i++; > print $j; > }' 1 2 3 4 $
$ perl -wle ' my $i = 1; my $j; while ( $i < 5 ) { $j = $i++; print $j; }' 1 2 3 4 $

You can see, each print prints the value of $i and $j doesn't "remember" its previous content.

update: sentence rewritten

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759684]
[marto]: "no it's not that"...."weirdos "...
[marto]: List EXE_FILES installed by CPAN so a couple of people suggest that your code looks obfuscated. I'd have to ageree, from the perspective of those who can't follow all of that one liner, it doesn't read well
Veltro is a weirdo, obsessed with whitespace
[marto]: to use the word "obsession" when so few people have said so little about it is grasping at staws
marto wishes tye was around, he's so much better at this sort of thing
usemodperl likes tye!
usemodperl tye  too
[choroba]: Re^3: LiBXML: New markup while preserving earlier tags? would benefit from a couple of test cases
usemodperl meant tye&nbsp;
usemodperl pokes Veltro with line noise

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-06-24 16:01 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.