How to read gz file line by line in Perl6

  • A+
Category:Languages

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; } 

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

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

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

thanks

 


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; 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: