gpt4 book ai didi

perl - 为什么我可以打开undef?

转载 作者:行者123 更新时间:2023-12-04 07:02:43 25 4
gpt4 key购买 nike

以下不会死:

open my $in, '<', undef or
die q{couldn't open undef};
print <$in>;

这也不行:
open my $in, '>', undef or
die q{couldn't open undef};
print $in 'hello';

我不明白为什么这两个都不死。怎么可能开通 undef可能会成功?
我发现这一点的原因是与我一起工作的一个人这样做了:
open my $in, '>', $ARGV[0] or die q{couldn't open $ARGV[0]};

他认为如果没有传入参数,这会杀死脚本(我知道这不是最干净的方法,但我认为它不起作用)。

我正在使用草莓 5.16.1。

最佳答案

perldoc -f open :

As a special case the three-argument form with a read/write mode and the third argument being undef:

open(my $tmp, "+>", undef) or die ...

opens a filehandle to an anonymous temporary file.

关于perl - 为什么我可以打开undef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20155221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com