The one thing I did that produced different results was to change the open statement to use '<:encoding(UTF-8)' for the mode instead of '<', but that transforms everything (not just the chars, but also the words) into stuff like "\x{ff11}", which does not seem useful to me.
That is the correct fix. Dumper produces Perl code, primarily for debugging purposes. When it comes to characters where encoding is likely to matter, it uses escapes to avoid mixups. As a debugging tool, it rather produce some harder to read output then producing output that looks wrong because the caller didn't properly encode the output.
If you hadn't used Dumper (just printed the string) and if you encoded your output (use open ':std', ':locale';), then you would get the actual characters.
(Each of the graphemes you posted were represented by a single character, so I didn't bother using \P{M}.)
use strict;
use warnings;
use open ':std', ':locale';
use Data::Dumper qw( Dumper );
my $file = do {
open(my $fh, '<:encoding(UTF-8)', 'jap') or die $!;
local $/;
<$fh>
};
print(Dumper($file));
print("[$_]") for $file =~ /(.)/sg;
print("\n");
$VAR1 = "\x{6301}\x{3063}\x{3066}\x{884c}\x{304f}
";
[持][っ][て][行][く][
]
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.