in reply to (Ovid) Re: I just realized that FILEHANDLES violate use strict
in thread I just realized that FILEHANDLES violate use strict

When using a scalar variable, open (invisibly) returns an IO::Handle object. IO::Handle, as it happens, generates an "anonymous" typeglob using the Symbol module.

Perl doesn't actually have true anonymous typeglobs (as they must be (er.. make that) start as (see Update2 below) part of a symbol table), so what the Symbol module does to create pseudo-anonymous typeglobs is create a unique, unused-by-anything-else entry in the symbol table for the Symbol:: package. It then returns a (typeglob) reference to that symbol table entry.

So, uh, I guess the answer is: yes, it is really a typeglob, but no, it's not really lexically scoped (well, the ref is, but not the actual typeglob that it points to).

Update: Well, ok. There's some internal magic that mucks about with the name of the typeglob entry (as evidenced by Juerd's post), but the principle is the same.

Update2: Well, as tye points out, the internal magic of open uses the magic of local to break the glob away from its symbol table of origin (which also, incidentally, happens to be the same package the open statement is in, instead of a seperate package like Symbol) and make it truly lexical.

This has the added benefit that the name of the symbol used is irrelevent, so open uses the name of the original variable (which, of course, Symbol wouldn't have access to anyway). This allows warnings and errors to report the name of the opened filehandle as the name of the variable used to read from the file (and be right... most of the time).

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.

  • Comment on (bbfu) (IO::Handle and Symbol) Re: (Ovid) Re: I just realized that FILEHANDLES violate use strict
  • Download Code