in reply to Guessing encode text file

Wouldn't it be more handy to use the error fallback options of the decode function from the standard module Encode? For example, you can set it to throw exception if text cannot be decoded as UTF-8 and catch the exception:
my $characters = eval { decode utf8 => $bytes, Encode::FB_CROAK }; unless (defined $characters) { warn "$filename does not contain valid UTF-8 data, skipping"; next FILE; } # INSERT INTO ...
(untested)

Replies are listed 'Best First'.
Re^2: Guessing encode text file
by karlgoethebier (Abbot) on Jan 20, 2014 at 19:39 UTC