1

在此处输入图像描述

它似乎filehandleformat没有任何前缀,所以我无法通过%{*spud}.

有什么我想念的吗?

更新

如何访问format?为什么$fd=*STDOUT$fd=\*STDOUT两者都有效?

更新2

代码:

package Foo;
our $spud = 'a scalar';
our @spud = 'an array';
our %spud = (a => 'hash');
sub spud {}
format spud =
.
open 'spud', $0; 

my $stash = \%Foo::;
my $name  = 'spud';
my $glob  = $$stash{$name};

for my $type (qw(SCALAR ARRAY HASH CODE IO FORMAT)) {
    #this works
    #print *$glob{$type}, $/; 
    #this doesn't work,only output one row of scalar                                  
    print *{$FOO::{spud}}{$type}, $/; 
}

输出:

[root@perl]# perl tb
SCALAR(0xa4dcf30)





[root@perl]# 
4

2 回答 2

2
{package Foo;
    our $spud = 'a scalar';
    our @spud = 'an array';
    our %spud = (a => 'hash');
    sub spud {}
    format spud =
.
    open 'spud', $0;
}

my $stash = \%Foo::;
my $name  = 'spud';
my $glob  = $$stash{$name};

for my $type (qw(SCALAR ARRAY HASH CODE IO FORMAT)) {
     print *$glob{$type}, $/;
}

印刷:

标量(0x810070)
数组(0x81c750)
哈希(0x81bb00)
代码(0x81bbd0)
IO::句柄=IO(0x81b670)
格式(0x81bc40)
于 2011-07-21T14:51:35.310 回答
0

*spud 将为您提供 glob 类型的文件句柄。请参见此处:Typeglobs 和文件句柄

于 2011-07-21T13:47:40.847 回答