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

Re: Re-gaining 'O's

Thread Previous | Thread Next
From:
Juerd Waalboer
Date:
August 26, 2008 02:32
Subject:
Re: Re-gaining 'O's
Message ID:
20080826093153.GH10987@c4.convolution.nl
At this time I lack the time to answer the entire mail, but one part I
can comment on:

Russ Allbery skribis 2008-08-26  0:27 (-0700):
> But this still feels wrong to me; everywhere I do file IO in a module, I'm
> required to add these encode and decode statements all over the place or
> add IO layers, which aren't backward compatible with older versions of
> Perl?  Surely that can't be right.

Yes, that's right.

Numbers always needed some conversion before they could fit in binary
form. That's what pack and unpack are for, or on another level
conversion to a string of (ASCII) digits.

Text strings need the same treatment if your encoding is not a "single
byte = single character" encoding. Continuous unpacking and packing...
I mean decoding and encoding of course.

>  while (<DATA>) {
> +    $_ = decode ('utf-8', $_);
(...)
>      while (<DATA>) {
> +        $_ = decode ('utf-8', $_);
(...)
>      while (<DATA>) {
> +        $_ = decode ('utf-8', $_);
(...)
> +        print TMP encode ('utf-8', $_);
(...)
>      while (<TMP>) {
> +        $_ = decode ('utf-8', $_);
(...)
>      while (<DATA>) {
> +        $_ = decode ('utf-8', $_);
(...)

Looks sane, but it'd be easier with a layer. binmode DATA,
":encoding(utf-8)" and you don't need all those decodes anymore.
-- 
Met vriendelijke groet,  Kind regards,  Korajn salutojn,

  Juerd Waalboer:  Perl hacker  <#####@juerd.nl>  <http://juerd.nl/sig>
  Convolution:     ICT solutions and consultancy <sales@convolution.nl>
1;

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