:utf8",$path) 是什么?-6ren"> :utf8",$path) 是什么?-可以将编码为 utf-8 的文件白化,如下所示: open my $fh,">:utf8","/some/path" or die $!; 如何使用 IO::File 获得相同的结果,最好是 1 行?-6ren">
gpt4 book ai didi

perl - Perl 的 IO::File 等价于 open($fh, ">:utf8",$path) 是什么?

转载 作者:行者123 更新时间:2023-12-04 17:44:07 24 4
gpt4 key购买 nike

可以将编码为 utf-8 的文件白化,如下所示:

open my $fh,">:utf8","/some/path" or die $!;

如何使用 IO::File 获得相同的结果,最好是 1 行?
我得到了这个,但它是否也能做到这一点,并且可以在 1 行中完成吗?
my $fh_out = IO::File->new($target_file, 'w');
$fh_out->binmode(':utf8');

作为引用,脚本开始如下:
use 5.020;
use strict;
use warnings;
use utf8;
# code here

最佳答案

是的,您可以 do it in one line .

open accepts one, two or three parameters. With one parameter, it is just a front end for the built-in open function. With two or three parameters, the first parameter is a filename that may include whitespace or other special characters, and the second parameter is the open mode, optionally followed by a file permission value.

[...]

If IO::File::open is given a mode that includes the : character, it passes all the three arguments to the three-argument open operator.


所以你只要这样做。
my $fh_out = IO::File->new('/some/path', '>:utf8');
和你的第一个 open 一样线,因为它通过了。

关于perl - Perl 的 IO::File 等价于 open($fh, ">:utf8",$path) 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42165728/

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