如何在Perl6中逐行读取gz文件 [英] How to read gz file line by line in Perl6

查看:60
本文介绍了如何在Perl6中逐行读取gz文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Perl6 中逐行读取一个巨大的 gz 文件.

I'm trying to read a huge gz file line by line in Perl6.

我正在尝试做这样的事情

I'm trying to do something like this

my $file = 'huge_file.gz';
for $file.IO.lines -> $line {
    say $line;
}

但这会导致我的 UTF-8 格式错误.我看不到如何从帮助页面读取 gzipped 材料 https://docs.perl6.org/language/unicode#UTF8-C8https://docs.perl6.org/language/io

But this give error that I have a malformed UTF-8. I can't see how to get this to read gzipped material from the help page https://docs.perl6.org/language/unicode#UTF8-C8 or https://docs.perl6.org/language/io

我想完成与 Perl5 相同的事情:http://blog-en.openalfa.com/how-to-read-and-write-compressed-files-in-perl

I want to accomplish the same thing as was done in Perl5: http://blog-en.openalfa.com/how-to-read-and-write-compressed-files-in-perl

如何在 Perl6 中逐行读取 gz 文件?

How can I read a gz file line by line in Perl6?

谢谢

推荐答案

如果您正在寻求快速解决方案,您可以从 gzip 进程的标准输出管道中读取行:

If you are after a quick solution you can read the lines from the stdout pipe of a gzip process:

my $proc = run :out, "gzip", "--to-stdout", "--decompress", "MyFile.gz"

for $proc.out.lines -> $line {
    say $line;
}

$proc.out.close;

这篇关于如何在Perl6中逐行读取gz文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆