jbrugger has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I want to check the encoding of a file, since i need to convert all my templates to utf8, but not the ones that are utf8, since they will be double encoded (using iconf)
However, after supersearching i came up with the following possible solution:
for now, we started to use (opening each file and parsing it in the encoder):
Thanks!
I want to check the encoding of a file, since i need to convert all my templates to utf8, but not the ones that are utf8, since they will be double encoded (using iconf)
However, after supersearching i came up with the following possible solution:
This is not returning anything however.#!/usr/bin/perl -w use strict; use File::BOM qw( :all ); open_bom(FH, "test.txt", 'bytes'); my $encoding = get_encoding_from_filehandle(FH); print $encoding . "\n\n";
for now, we started to use (opening each file and parsing it in the encoder):
For the rest i did not find any other way of dertermining the encoding of a file, anyone knows what is wrong with File::BOM or does anyone have a better solution?use Encode::Guess; my $decoder = guess_encoding($arg->{String}, 'latin1'); if (ref($decoder)) { return 0; } else { return 1; }
Thanks!
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: how to check the encoding of a file
by ysth (Canon) on Apr 10, 2006 at 11:16 UTC | |
Re: how to check the encoding of a file
by graff (Chancellor) on Apr 11, 2006 at 02:34 UTC |
Back to
Seekers of Perl Wisdom