A filehandle is just a scalar

jdavidb on 2002-09-03T17:37:27

... or at least, it should be. Currently, a filehandle is a glob. Sort of.

From the point of view of perltie, a filehandle is a thingy that implements TIEHANDLE, WRITE, PRINT, PRINTF, READ, READLINE, GETC, CLOSE, UNTIE, and DESTROY. Or maybe just some of those. In fact, we might distinguish between read-only filehandles, write-only filehandles, and read and write filehandles by the methods implemented.

perltie will let you access that thingy through a tied glob, though, because a filehandle is a glob, more or less. These days, though, a filehandle to me looks like:

open my $fh, $filename or die;

In otherwords, a scalar. I already mentioned three types of filehandles you can have based on the set of methods implemented. What if, in tying a scalar, you had the option to implement some of these filehandle methods? A filehandle would simply be a special kind of scalar. This is where things are supposedly headed in the future, anyway, and it's where most of my code using non-tied filehandles is, now. Moreover, one of the primary uses for globs would go away.