Perl 6 Error Message: Invalid UTF-8 in <unit> Block

I am trying to read the downloaded html file

my $file = "sn.html"; my $in_fh = open $file, :r; my $text = $in_fh.slurp; 

and I get the following error message:

 Malformed UTF-8 in block <unit> at prog.p6 line 10 

How to avoid this and access the contents of the file?

+5
source share
1 answer

If you do not specify the encoding when opening the file, it will accept utf8 . Apparently, the file you want to open contains bytes that cannot be interpreted as UTF-8. Hence the error message.

Depending on what you want to do with the contents of the file, you can either set the :bin named parameter to open the file in binary mode. Or you can use a special utf8-c8 encoding that will accept UTF-8 until it encounters bytes that it cannot encode: in this case, it will generate temporary code points.

See https://docs.perl6.org/language/unicode#UTF8-C8 for more details.

+9
source

Source: https://habr.com/ru/post/1275917/


All Articles