Before the advent of IO::File
, which provides an object-oriented API for accessing files, there was no alternative to using file handles. The problem with file handles come when writing (or using) modules. If a routine in a module needs to open a file, and uses FILE
for the file handle, the only way to avoid smashing some other FILE
is to localize the file handle using the
idiom. This guarantees that any other variables named FILE
will be restored at the end of the routine that does the localizing.
If you're writing a simple script, there's little reason to do this yourself. If you're writing a module, the better thing to do now is use IO::File for file access.