Perl 中文件句柄的内置名称是什么?
What is a built-in name for a filehandle in Perl?
perl -f ref 列出的名称中的 None 似乎是文件句柄。下面的代码 returns GLOB,所以看起来 filehandle 在内部映射到或管理为 typeglob。对吗?
open FH, '>', "out.txt";
my $ref = \*FH;
print "ref $ref:", ref $ref, "\n";
文件句柄是否有自己的类型名称?
Does a filehandle have its own type name?
IO
.
$ perl -MDevel::Peek -e'Dump(*STDOUT{IO});'
SV = IV(0x3ba7118) at 0x3ba7128
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x3bc4390
SV = PVIO(0x3bc8668) at 0x3bc4390
REFCNT = 3
FLAGS = (OBJECT)
STASH = 0x3bc3fa0 "IO::File"
IFP = 0x3bbe180
OFP = 0x3bbe180
DIRP = 0x0
LINES = 0
PAGE = 0
PAGE_LEN = 60
LINES_LEFT = 0
TOP_GV = 0x0
FMT_GV = 0x0
BOTTOM_GV = 0x0
TYPE = '>'
FLAGS = 0x0
从技术上讲,一个 IO
对象可以有三个与之关联的句柄:一个输入文件句柄 (IFP
)、一个输出文件句柄 (OFP
) 和一个目录句柄(例如,使用 opendir
、DIRP
创建)。通常,只设置输入和输出句柄之一,或者将它们都设置为同一个句柄。由于单独的文件和目录句柄,执行 open(FOO, ...); opendir(FOO, ...); <FOO>; readdir(FOO);
会很好。
it seems filehandle is internally mapped to or managed as a typeglob. Is that correct?
文件和目录 IO 对象通常都封装在一个 glob 中,是的。
但这不是必需的。
$ perl -E'
my $fh = "STDOUT"; say($fh "$fh");
my $fh = *STDOUT; say($fh "$fh");
my $fh = \*STDOUT; say($fh "$fh");
my $fh = *STDOUT{IO}; say($fh "$fh");
'
STDOUT # Name
*main::STDOUT # Glob
GLOB(0x1175a48) # Reference to a glob. (This is returned by open $fh)
IO::File=IO(0x1175a60) # Reference to a (blessed) IO.
None 似乎是文件句柄。下面的代码 returns GLOB,所以看起来 filehandle 在内部映射到或管理为 typeglob。对吗?
open FH, '>', "out.txt";
my $ref = \*FH;
print "ref $ref:", ref $ref, "\n";
文件句柄是否有自己的类型名称?
Does a filehandle have its own type name?
IO
.
$ perl -MDevel::Peek -e'Dump(*STDOUT{IO});'
SV = IV(0x3ba7118) at 0x3ba7128
REFCNT = 1
FLAGS = (TEMP,ROK)
RV = 0x3bc4390
SV = PVIO(0x3bc8668) at 0x3bc4390
REFCNT = 3
FLAGS = (OBJECT)
STASH = 0x3bc3fa0 "IO::File"
IFP = 0x3bbe180
OFP = 0x3bbe180
DIRP = 0x0
LINES = 0
PAGE = 0
PAGE_LEN = 60
LINES_LEFT = 0
TOP_GV = 0x0
FMT_GV = 0x0
BOTTOM_GV = 0x0
TYPE = '>'
FLAGS = 0x0
从技术上讲,一个 IO
对象可以有三个与之关联的句柄:一个输入文件句柄 (IFP
)、一个输出文件句柄 (OFP
) 和一个目录句柄(例如,使用 opendir
、DIRP
创建)。通常,只设置输入和输出句柄之一,或者将它们都设置为同一个句柄。由于单独的文件和目录句柄,执行 open(FOO, ...); opendir(FOO, ...); <FOO>; readdir(FOO);
会很好。
it seems filehandle is internally mapped to or managed as a typeglob. Is that correct?
文件和目录 IO 对象通常都封装在一个 glob 中,是的。 但这不是必需的。
$ perl -E'
my $fh = "STDOUT"; say($fh "$fh");
my $fh = *STDOUT; say($fh "$fh");
my $fh = \*STDOUT; say($fh "$fh");
my $fh = *STDOUT{IO}; say($fh "$fh");
'
STDOUT # Name
*main::STDOUT # Glob
GLOB(0x1175a48) # Reference to a glob. (This is returned by open $fh)
IO::File=IO(0x1175a60) # Reference to a (blessed) IO.