[lug] perl question
Michael J. Hammel
mjhammel at graphics-muse.org
Sun Apr 9 13:33:22 MDT 2000
Thus spoke Hugh Brown
> while (<$filename>){
>
> blah;
> blah;
> blah;
> }
>
> why is it that if you do another while loop similar to the above that
> nothing happens?
The loop exits when the EOF is reached, but the file is still open. You
need to reset the file pointer to the beginning of the file using seek:
seek(FD, 0, 0)
BTW - you're code isn't what you really want. Open the file first and use the
file descriptor returned from the open(). That way you can leave the file
open.
open(FD, $filename);
while ( <FD> )
{
blah;
}
seek (FD, 0, 0);
while ( <FD> )
{
blah;
}
close(FD);
Hey Tony - check me on that <FD> bit. I'm not exactly sure what the <>
bracketing is for.
--
Michael J. Hammel | Often, when I am reading a good book, I stop
The Graphics Muse | and thank my teacher. That is, I used to,
mjhammel at graphics-muse.org | until she got an unlisted number.
http://www.graphics-muse.com Deep Thoughts, Jack Handey
More information about the LUG
mailing list