Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by linuxer (Deacon)
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


Comment on Re: How to Properly Clear Variables for reuse in a loop
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-09-24 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (246 votes), past polls