Perl 5 has the encoding
pragma or the Filter::Encoding
module, however, I have not found anything similar in Perl 6. I guess eventually source filters will be created, but for the time being, can you use other encodings in Perl 6 scripts?
-
1I note @ikegami's removal of the `perl` tag. I've done a bit of research and wanted to save it here in a comment. **1.** There's a clear StackOverflow community consensus that the primary purpose of tags is to attract attention of answerers. **2.** [The only answer to the Meta SO question *Should “equivalent feature” questions include two language tags?*](https://meta.stackoverflow.com/a/366245/1077672) is the opinion that only one tag should be used. The lack of an accepted mark and the comments on that meta SO answer suggest it's perhaps not clear cut but there's also no competing answer. – raiph Oct 05 '18 at 18:14
-
@ralph, There's no help a Perl5 programmer can give. – ikegami Oct 05 '18 at 18:39
-
@ikegami actually, given that the encoding pragma was obsoleted, and moved to a non-core module like Filter::Encoding, there might be some advice on why that happened and why it wasn't actually a good idea. FWIW, that's why I included the tag when I found the linked material a bit confusing, re: if my first sentence is really true. – jjmerelo Oct 06 '18 at 07:52
-
1@jjmerelo, It's cause encoding didn't actually decode the script so much as decode string literals after they were parsed. Yeah, that's as wonky as it sounds. Nothing relevant to the question. [Ask Question](https://stackoverflow.com/questions/ask) if you want the details. – ikegami Oct 06 '18 at 07:57
-
@ikegami Yes. I don't question your moderator like activity. You always seem very much on the ball. I just wanted to help us P6ers be as respectful of your time and that of other non-P6er P5ers as we can. I've seen this `perl6` *and* `perl` tagging issue come up before and have researched it on meta.SO before. This time I decided to record a summary of this particular aspect of it in a comment to raise awareness of it and save me having to repeat the (re)search. – raiph Oct 06 '18 at 11:16
-
1@jjmerelo Aiui tagging `perl` or not boils down to a judgment call. There's some weak guidance provided by the meta.SO Q+A I linked plus some similar ones. My read of that guidance is to not add a `perl` tag except in rare circumstances where someone absolutely has to know the P5 feature in depth. Much more importantly, a long established SO consensus is that tags are primarily for helping answerers, not questioners or searchers, so the final call on judgments about tagging are properly made by folk like ikegami. In summary, everything seems to have happened as it's supposed to happen. :) – raiph Oct 06 '18 at 12:27
2 Answers
Rakudo currently supports an --encoding=
option, so you might in theory be able to write a script in a different character encoding, and call it with perl6 --encoding=utf16 yourscript.p6
. But in my experiments, I haven't managed to get it working with anything except utf8
, and even if it worked, specifying --encoding
on the command line would be a big no go for me.
So the operational answer is: currently no.
(And I don't think anybody else has asked for it yet...)

- 12,710
- 1
- 41
- 63
You cannot write your Perl 6 script in anything except utf8. I don't think there will ever be any other encoding you will be allowed to write your script in, as utf8 is basically the universal standard. Benefits like not having endianess and being back compatible with ASCII are some reasons it has become the standard and not things like utf16 or utf32.
Maybe there was a time before when such a thing may have been useful, but today I do not see that being the case. All text editors in common usage I know of default to utf8, and having files in multiple formats makes it more difficult to share your Perl 6 programs with others. There are plenty of reasons to want to use other encodings external to Perl 6 (writing to files, reading files etc.) but I don't see adding filters as smart move.

- 496
- 3
- 5
-
UTF-8 being the universal standard is rather optimistic thinking. – matthias krull Oct 05 '18 at 07:03
-
1@matthiaskrull Not universal in the sense that no one will ever have or encounter a source file in some encoding other than ascii/utf8. But if they want to use it as code then it's far more sensible that they convert it to utf8, which can encode any Unicode text, and has no practical downsides (afaik; do you know of any?), than adopt any other approach to using it in almost any conceivable scenario. Thus that's what almost all devs will do. So, "basically universal" in that sense. Am I missing anything? – raiph Oct 05 '18 at 17:38