On Sun, Aug 05, 2001 at 09:05:27AM -0400, Greg London wrote:
> Hey, since when could perl do this?
>
> open(INPUT,$name);
> my $line = < 'INPUT' >;
> close(INPUT);
I couldn't get this example to work, perhaps you meant:
open('INPUT',$name);
my $line = <INPUT>;
close('INPUT');
> taking a string to figure out what the
> filehandle is? is that what's going on?
I think Perl has been able to do this forever. What you think of as
filehandles are barewords, which are just strings. In the absence of
'use strict 'subs'' (a relatively new feature), barewords are usually
parsed as strings:
$x = INPUT; # no strict subs and no sub named INPUT
print $x; # prints 'INPUT'
Nowadays, the most popular uses of barewords are in JAPHs and buggy
code that doesn't use strict. But since so many people learned to use
them for i/o, they are still allowed where a filehandle might appear,
even under strict.
What a filehandle REALLY is, at least before 5.6, is an attribute of a
glob that came from the symbol table. Symbol.pm and related modules
(including IO::File) somewhat hide this, but Perl has always had this
mysterious link between its namespace management (symbol table) and
i/o systems.
Since the symbol table indexes variables by their string names,
filehandles are identifiable by simple strings. Through a history of
changing preferences, efficiency hacks, and DWIM attempts, the
following statements have become equivalent, at least in their effect
on the filehandle:
open(INPUT,$name);
open('INPUT',$name);
open(*INPUT,$name);
open('*INPUT',$name);
open(\*INPUT,$name);
open(::INPUT,$name);
open('main::INPUT',$name);
# etc. etc.
> !?!?
> Greg
>
Hope this helps.
-John
--
John Tobey, late nite hacker <[EMAIL PROTECTED]>
``I just dont want to worry about my word processor dropping its core.
It simply isnt my job to whip out GDB and debug my word processor.''
-Emily K. Dresner-Thornber