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

Hi friends,

This is a bit urgent. Does perl version 4.0 support pack/unpack fuction to convert a string from iso-western european to UTF-8? I mean does it support the perl statement

$key = pack( 'C*',unpack( 'U*', $key ) );
Pls shed some light!!!!

update (broquaint): added formatting

20030808 Edit by jeffa: Changed title from 'pack function '

Replies are listed 'Best First'.
Re: Convert to UTF-8 on Perl 4
by liz (Monsignor) on Aug 08, 2003 at 12:21 UTC
    If I would need to do this in Perl 4, I would take the right bits out of NexTrieve::UTF8 (especially the definition of the "@iso88591" array) and use the is88591 function:
    sub iso88591 { $_[0] =~ s#([\x80-\xFF])#$iso88591[ord($1)-0x80]#sge; } #iso88591
    thus:
    iso88591( $key );
    There are probably other modules out there that would work under Perl 4, but I'm familiar with this particular module (because I wrote the script that generates it ;-).

    Liz

Re: Convert to UTF-8 on Perl 4
by gmax (Abbot) on Aug 08, 2003 at 12:13 UTC

    See it by yourself at the pack docs.

    Unicode support didn't exist in Perl 5.005_03 and it is present in Perl 5.6

    Therefore the answer is NO ;)

     _  _ _  _  
    (_|| | |(_|><
     _|   
    
Re: Convert to UTF-8 on Perl 4
by castaway (Parson) on Aug 08, 2003 at 12:10 UTC
    $ perl -v This is perl, version 4.0 $RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $ Patch level: 36 Copyright (c) 1989, 1990, 1991, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 4.0 source +kit. $ perl -we'$key = pack( "C*", unpack("U*", "AB")); print "$key\n";' $
    Doesn't appear to do diddly. Outputs AB on 5.8.0 (different machine), and Invalid type in unpack: 'U' at -e line 1. using 5.005 on the same machine..

    (Looks like a 'no' to me)

    C.