Perl:在文档中内联选择FD不适用于严格的参考(Perl: Inline selection of FD as in docs does not work with strict refs)

编程入门 行业动态 更新时间:2024-10-25 08:26:58
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.

更多推荐

本文发布于:2023-07-24 20:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250586.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内联   不适用于   文档   Perl   FD

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!