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 =
     "\x[1200]\x[2D80]\x[4DFC]\x[AAAA]\x[2CA4]\x[2C8E]";

my $file = "/home/doom/tmp/stuff_in_utf16.txt";
my $fh = $file.IO.open( :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

Reply via email to