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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-12-16 07:58 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (449 votes). Check out past polls.