http://qs1969.pair.com?node_id=789251

roadrunner has asked for the wisdom of the Perl Monks concerning the following question:

I'm using ActiveState Perl 5.6 on a Win32 platform and need to install "Encode" for some utf-8 shenanigans. However I get the following error from PPM when trying:
PPM> install Encode Install package 'Encode?' (y/N): y Installing package 'Encode'... Downloading http://ppm.activestate.com/PPMPackages/5.6/MSWin32-x86-mul +ti-thread/Encode-1.99.tar.gz ... Error installing package 'Encode': Error reading http://ppm.activestat +e.com/PPMPackages/5.6/MSWin32-x86-multi-thread/Encode-1.99.tar.gz
I've checked the repository and it isn't there. Does anyone know:

(1) Where I could get hold of this module from ?
(2) An alternative way of decoding UTF-8 strings (must be compatible with Win32 5.6) ?

Thanks.

Replies are listed 'Best First'.
Re: Encode fails to install on Win32 5.6
by ikegami (Patriarch) on Aug 17, 2009 at 19:28 UTC
    I thought support for non-ASCII characters was only added in 5.8, so decoding a string it next to impossible in 5.6. Changing the encoding of a string is possible, of course. Text::Iconv can do that, but since it relies on an external library, it might be tricky to install in Windows.
      No, it was added in 5.6.0, and remained in various states of broken until 5.8 perldelta56

      --
      In Bob We Trust, All Others Bring Data.

        It had the UTF8 flag? Ah ok. My Windows machine (which has 5.6) is down at the moment, so I couldn't test. It's been a long time since I touched 5.6

        Update: Now that it's back up,

        >c:\progs\perl561\bin\perl -MDevel::Peek -wle"$x=chr(0x2660); print le +ngth $x; Dump $x" 1 SV = PV(0x183eb18) at 0x1832a0c REFCNT = 1 FLAGS = (POK,pPOK,UTF8) PV = 0x182013c "\342\231\240"\0 CUR = 3 LEN = 4
      Text::Iconv can do that, but since it relies on an external library, it might be tricky to install in Windows.

      There's a ppm for Text-Iconv-1.2 available for 5.6 at the uwinnipeg rep:
      ppm install http://theoryx5.uwinnipeg.ca/ppmpackages/Text-Iconv.ppd
      Cheers,
      Rob
Re: Encode fails to install on Win32 5.6
by belg4mit (Prior) on Aug 17, 2009 at 19:28 UTC
    Some code from Text::FIGlet might be of some use to you:
    sub UTF8ord{ my $str = shift || $_; my $len = length ($str); return ord($str) if $len == 1; #This is a FIGlet specific error value return 128 if $len > 4 || $len == 0; my @n = unpack "C*", $str; $str = (($n[-2] & 0x3f) << 6) + ($n[-1] & 0x3f); $str += (($n[-3] & 0x1f) << 12) if $len ==3; $str += (($n[-3] & 0x3f) << 12) if $len ==4; $str += (($n[-4] & 0x0f) << 18) if $len == 4; return $str; } sub UTF8chr{ my $ord = shift || $_; my @n; #x00-x7f #1 byte if( $ord < 0x80 ){ @n = $ord; } #x80-x7ff #2 bytes elsif( $ord < 0x800 ){ @n = (0xc0|$ord>>6, 0x80|$ord&0x3f ); } #x800-xffff #3 bytes elsif( $ord < 0x10000 ){ @n = (0xe0|$ord>>12, 0x80|($ord>>6)&0x3f, 0x80|$ord&0x3f ); } #x10000-x10ffff #4 bytes elsif( $ord<0x20000 ){ @n = (0xf0|$ord>>18, 0x80|($ord>>12)&0x3f, 0x80|($ord>>6)&0x3f, 0x80|$ord&0x3f); } else{ warn "Out of range for UTF-8: $ord"; } return pack "C*", @n; }
    I've tested it as far back as 5.00503 IIRC.

    --
    In Bob We Trust, All Others Bring Data.

Re: Encode fails to install on Win32 5.6
by grantm (Parson) on Aug 17, 2009 at 21:11 UTC
    I'm using ActiveState Perl 5.6 on a Win32 platform and need to install "Encode" for some utf-8 shenanigans.

    No, you need to upgrade. By all means stay on an older release if it does everything you need. But in your case it clearly doesn't and even if you could install the Encode module Perl 5.6 is not a sensible choice for working with UTF8 data. Do yourself a favour and install Strawberry Perl or the latest ActiveState build.

      Encode can not be installed on 5.6. It's tied up with 5.8 features and even the Makefile.PL requires 5.007003 at least.