develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #119239] started out as doc clarification needed in 'eval...but...

Thread Previous | Thread Next
From:
Eric Brine
Date:
August 15, 2013 20:37
Subject:
Re: [perl #119239] started out as doc clarification needed in 'eval...but...
Message ID:
CALJW-qHDXtRAJv=yH6qCFrAa+fQtn6E47SkEVFasWwo8RzDMaQ@mail.gmail.com
On Thu, Aug 15, 2013 at 4:32 PM, Eric Brine <ikegami@adaelis.com> wrote:

> On Thu, Aug 15, 2013 at 3:43 PM, Linda Walsh via RT <
> perlbug-followup@perl.org> wrote:
>
>> Points) A) - "(to myself as much as anyone)" - use utf8 only applies to
>> source code not content strings, so my wonderings why the Japanese
>> INU(dog) YA(night) SHA(dividing point) came out "ok"
>
>
> $ perl -Mutf8 -E'say "\x{72AC}\x{591C}\x{53C9}"'
>
> Wide character in say at -e line 1.
> 犬夜叉
>
> File handles take bytes unless you arrange for an encoding layer to
> provide those bytes. That error message is a polite way of saying "I was
> able to detect that you gave me garbage, and I guessed at what you wanted".
>
> Now lets look at the following:
>
> $ perl -Mutf8 -E'say "\x51\x75\x65\x65\x6E\x73\x72\xFF\x63\x68\x65"'
> Queensr?che
>
> Perl issued no error message because you provided bytes (values in 0..255)
> as expected. Perl has no way to know you meant to output UTF-8.
>

The logic is simply equivalent to:

if ($str =~ /[^\x00-\xFF]/) {
    # ERROR
    warn("Wide character in say");
    utf8::encode($str);  # This might be what they meant
}
_write($str);

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About