Okay. I think I'm seeing why there are two camps. Some are saying
"Give file handles a distinct identity" (Charles Bailey and me being
most vocal), while others are saying "File handles don't need a
distinct identity, now that we have objects and anonymous globs" (Tom
Christiansen being most vocal).
Well, we're both right. It's a floor wax _and_ a dessert topping.
First, I agree with Tom that most new code should use FileHandle. I
have no qualms about recommending it. That's why I have put a lot of
effort into the FileHandle package.
However, while the interface of FileHandle seems straightfoward, its
implementation uses anonymous globs. And I consider the use of globs
(anonymous or otherwise) as file handles to be a kludge. (Datamation
defines a kludge as "an ill-assorted collection of poorly-matching
parts, forming a distressing whole".)
You see, globs are symbol table entries. And there is *NO*REASON* why
the concept of file handles should be tied to the concept of symbol
tables. Granted we can now make "anonymous" globs. But that just
adds a hack on top of the kludge. I want something cleaner, better.
Tom hates the ^FH syntax. Personally, I don't like it much either.
But in order to lexically scope a Perl variable, that variable must
have a name, so I just tried to come up with a unique name. But if
there were another way to create a lexically scoped file handle --
which is NOT the same as "new FileHandle", because I'm talking about
implementation of FileHandle::new, not interface -- then the issue
would disappear.
(Mind you, this analysis assumes that Larry provides or allows
two-parameter ref() or $*glob{FILEHANDLE}, which solves the related
but distinct issue of aliasing named file handle without disturbing
entire symbol table entries.)
So I propose a facility for creating anonymous entities without
lexical scoping or anonymous globs:
anonymous(TYPE)
where:
anonymous("SCALAR") means do { my $x; \$x }
anonymous("ARRAY") means do { my $x; \@x }
anonymous("HASH") means do { my $x; \%x }
anonymous("FILEHANDLE") means do { my ^x; \^x } # :-)
anonymous("GLOB") means do { local *::X; \delete $::{X} }
So, what do you think?
--
Chip Salzenberg, aka <chs@nando.net>
"Hey, it's the Miss Alternate Universe Pageant!"
-- Crow T. Robot, MST3K: "Stranded In Space"
"Give file handles a distinct identity" (Charles Bailey and me being
most vocal), while others are saying "File handles don't need a
distinct identity, now that we have objects and anonymous globs" (Tom
Christiansen being most vocal).
Well, we're both right. It's a floor wax _and_ a dessert topping.
First, I agree with Tom that most new code should use FileHandle. I
have no qualms about recommending it. That's why I have put a lot of
effort into the FileHandle package.
However, while the interface of FileHandle seems straightfoward, its
implementation uses anonymous globs. And I consider the use of globs
(anonymous or otherwise) as file handles to be a kludge. (Datamation
defines a kludge as "an ill-assorted collection of poorly-matching
parts, forming a distressing whole".)
You see, globs are symbol table entries. And there is *NO*REASON* why
the concept of file handles should be tied to the concept of symbol
tables. Granted we can now make "anonymous" globs. But that just
adds a hack on top of the kludge. I want something cleaner, better.
Tom hates the ^FH syntax. Personally, I don't like it much either.
But in order to lexically scope a Perl variable, that variable must
have a name, so I just tried to come up with a unique name. But if
there were another way to create a lexically scoped file handle --
which is NOT the same as "new FileHandle", because I'm talking about
implementation of FileHandle::new, not interface -- then the issue
would disappear.
(Mind you, this analysis assumes that Larry provides or allows
two-parameter ref() or $*glob{FILEHANDLE}, which solves the related
but distinct issue of aliasing named file handle without disturbing
entire symbol table entries.)
So I propose a facility for creating anonymous entities without
lexical scoping or anonymous globs:
anonymous(TYPE)
where:
anonymous("SCALAR") means do { my $x; \$x }
anonymous("ARRAY") means do { my $x; \@x }
anonymous("HASH") means do { my $x; \%x }
anonymous("FILEHANDLE") means do { my ^x; \^x } # :-)
anonymous("GLOB") means do { local *::X; \delete $::{X} }
So, what do you think?
--
Chip Salzenberg, aka <chs@nando.net>
"Hey, it's the Miss Alternate Universe Pageant!"
-- Crow T. Robot, MST3K: "Stranded In Space"