in reply to Unicode UTF16 - Unknown encoding error

'Unknown encoding 'UTF16' at sample.pl...'.

You want "UTF-16" or "UTF-16LE". See Encode::Unicode. Also, Encode has from_to, so I'd probably write

use Encode qw(from_to); open (FSIN, "$_")||die ("Unable to open SGML.3d file $_"); my $sfile = <FSIN>; from_to($sfile,'UTF-16LE','ascii'); # or latin1, iso-8859-1 ...

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Unicode UTF16 - Unknown encoding error
by Anonymous Monk on Jun 25, 2007 at 11:50 UTC
    Shmem, Still I'm getting the same error --B
      Looking into the Encode Module -
      sub getEncoding { my ($class, $name, $skip_external) = @_; ref($name) && $name->can('renew') and return $name; exists $Encoding{$name} and return $Encoding{$name}; my $lc = lc $name; exists $Encoding{$lc} and return $Encoding{$lc}; my $oc = $class->find_alias($name); defined($oc) and return $oc; $lc ne $name and $oc = $class->find_alias($lc); defined($oc) and return $oc; unless ($skip_external) { if (my $mod = $ExtModule{$name} || $ExtModule{$lc}){ $mod =~ s,::,/,g ; $mod .= '.pm'; eval{ require $mod; }; <--- HERE exists $Encoding{$name} and return $Encoding{$name}; } } return; }

      it seems that on the line marked with <--- HERE the necessary encodings are loaded at runtime. I don't know about perl2exe, PerlAPP or such, but it will definitely not know what modules your script needs without running it.

      Put this at the end of your script:

      print STDERR "$_\n" for grep {/Encode/} sort keys %INC;

      and include explicitly any Encode/*.pm files you see. I guess you need to include, Encode/Unicode.pm, so start your script with

      use Encode; use Encode::Unicode;

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        Many Thanks shmem! It is working fine.
      Maybe you need binmode on that filehandle? Windows almost always needs binmode.

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum