Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Help with for loop

by BrowserUk (Pope)
on Sep 12, 2013 at 02:22 UTC ( #1053638=note: print w/replies, xml ) Need Help??

in reply to Help with for loop

What am I doing wrong?

You are expecting to be able to re-read your file each time you iterate your for loop. But that is not how IO works (in any language).

Files read from beginning to end and then stop.

If you want to re-read your file each time around your for loop, you will need to either:

  • Re-open the file each time.

    Ie. put the open & close inside the for loop.

  • Or "rewind" the file each time you iterate the for loop.

    Ie. Add a line: seek NB_FILE, 0, 0; as the first line inside the for loop.

    See seek() for details.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2016-10-27 22:19 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (371 votes). Check out past polls.