develooper Front page | perl.perl6.users | Postings from April 2020

Using slurp to read in a utf16 file

Thread Next
Joseph Brenner
April 26, 2020 22:20
Using slurp to read in a utf16 file
Message ID:
Looking at the documentation for slurp, it looks as though there's a
convenient "enc" option you can use if you're not reading utf8 files.
So I thought this would work:

   my $contents = slurp $file, enc => "utf16";

It's not doing what I expected... Raku acts like there's nothing in $contents.

Here's the test code I've been using:

# ሀⶀ䷼ꪪⲤⲎ
my $unichar_str =

my $file = "/home/doom/tmp/stuff_in_utf16.txt";
my $fh = $ :w, :enc("utf16") );
spurt $fh, $unichar_str;

# read entire file as utf16 Str
my $contents = slurp $file, enc => "utf16";
my $huh = $contents.gist;
say "contents: $contents";  #  contents:
say $contents.elems;        # 1

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About