Re-reading from already read filehandle

前端 未结 2 846
梦毁少年i
梦毁少年i 2021-01-01 20:22

I opened a file to read from line by line:

open(FH,\"<\",\"$myfile\") or die \"could not open $myfile: $!\";
while ()
{
    # ...do something
}
         


        
2条回答
  •  醉酒成梦
    2021-01-01 21:02

    You have a few options.

    • Reopen the file handle
    • Set the position to the beginning of the file using seek, as William Pursell suggested.
    • Use a module such as Tie::File, which lets you read the file as an array, without loading it into memory.

提交回复
热议问题