Perl:在文档中内联选择FD不适用于严格的参考(Perl: Inline selection of FD as in docs does not work with strict refs)
在perldoc print ,它说这应该工作:
print { $OK ? STDOUT : STDERR } "stuff\n";但它并不use strict ,而当我使用引号时
print { $OK ? "STDOUT" : "STDERR" } "stuff\n";我明白了
Can't use string ("STDOUT") as a symbol ref while "strict refs" in use ...我怎样才能让这个结构在不use strict情况下工作?
谢谢,
Mazze
In the perldoc for print, it says this should work:
print { $OK ? STDOUT : STDERR } "stuff\n";But it does not with use strict, and when I then use quotes like
print { $OK ? "STDOUT" : "STDERR" } "stuff\n";I get
Can't use string ("STDOUT") as a symbol ref while "strict refs" in use ...How can I get this structure to work without doing away with use strict?
Thanks,
Mazze
最满意答案
尝试这个:
print { $OK ? *STDOUT : *STDERR } "stuff\n";星号表示typeglob。 由于没有标记来表示文件句柄,因此您必须使用typeglob sigil(星号)。
Try this:
print { $OK ? *STDOUT : *STDERR } "stuff\n";The asterisk means the typeglob. Since there is no sigils to denote a file handle, you have to use the typeglob sigil, the asterisk, instead.
更多推荐
发布评论