in reply to Re: How do you open/read a text , without knowing its encoding, and remove any BOM if its utf, what do you use?
in thread How do you open/read a text , without knowing its encoding, and remove any BOM if its utf, what do you use?

Hi,

Encode::Guess does a fine job to detect the encoding. Read its documentation carefully on CPAN. To detect the encoding you can use something like:

open ( IN, "<", yourfile); my $bigstring = ""; my @content = <IN>; foreach my $tmp (@content) { $bigstring .= $tmp; } print "My file content encoding is: ", Encode::Guess->guess($bigstring +)->name;

Now you can decode and encode your data in the encoding you want. You need to have a strategy as to this matter. I recomment keeping it in UTF8 or 16 depending on the case. If you face BOM issues String::BOM is a good solution.

The following might help further: http://perldoc.perl.org/perluniintro.html

K

The best medicine against depression is a cold beer!
  • Comment on Re^2: How do you open/read a text , without knowing its encoding, and remove any BOM if its utf, what do you use?
  • Download Code