|P is for Practical|
Re: File Reading and Closing confusionby zentara (Archbishop)
|on Aug 08, 2010 at 14:03 UTC||Need Help??|
Actually, the topic is so broad and full of complexities, you need to ask a more specific question, showing some code.
As far as the code $text = <FILE> goes, look at the difference
In the abscence of a code example, these links may get you started. Basically, you can read a file line by line(default behavior), or sysread it in chunks. The diamond operator <> adds some magic. See diamond operator and "perldoc -f read"
Some filehandles you cannot seek on, like a socket filehandle. See read and sysread and run "perldoc -q file" and read all the sections. Remember, if you are on a unix style OS, you have file descriptors associated with each filehandle in /proc/$pid/fd. See How to close all open file descriptors after a fork? and close filehandles Remember, the file descriptors (numbers) in /proc/$pid/fd/ is where the real action takes place( at least on linux).... the filehandles are just convenience handles.
Alot of us Perl hackers are lazy, and don't close filehandles after use, just letting the system clean them up when the program exits. :-)
The one common gotcha encountered with the mix of unix and win32 systems, is that the 2 system have different line endings, so when the default line-by-line reading behavior is used to read a windows file on linux, proper line reading can get broken. Read "perldoc -f binmode".
I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku