Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Problems parsing UTF16 file

by Anonymous Monk
on Aug 10, 2012 at 09:37 UTC ( [id://986706]=note: print w/replies, xml ) Need Help??


in reply to Problems parsing UTF16 file

I don't know how to post the file and keep the encoding. So below is some of the file displayed using vi in the hex mode.

Like this

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw' pp '; use Encode::Detective qw' detect '; my $file = shift or die "Usage: $0 filename > data.pl \n"; my $data = do { open my($fh), '<:raw' , $file or die $!; local $/; <$fh>; }; my $encoding = detect($data); print q{my $data = }, pp($data), "; open my(\$fh), '<:$encoding', \\\$data or die; ... "; __END__ my $data = "\xFE\xFF\0h\0i\0\r\0\n"; open my($fh), '<:UTF-16BE', \$data or die; ...

Replies are listed 'Best First'.
Re^2: Problems parsing UTF16 file
by stu23 (Initiate) on Aug 10, 2012 at 17:52 UTC

    Mr Anonymous Monk, sir. Your code works fine also. Thank you very much. Stu

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-24 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found