Load Encode before trying to use Encode::resolve_alias

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-03-06 13:38:28 -03:00
2 changed files with 96 additions and 9 deletions

View File

@@ -3953,15 +3953,24 @@ sub main {
# Open the file and print the header to it.
if ( $archive_file ) {
my $need_hdr = $o->get('header') && !-f $archive_file;
my $charset = lc $o->get('charset');
if ( $charset ) {
$archive_fh = IO::File->new($archive_file, ">>:$charset")
or die "Cannot open $charset $archive_file: $OS_ERROR\n";
}
else {
$archive_fh = IO::File->new($archive_file, ">>")
or die "Cannot open $archive_file: $OS_ERROR\n";
}
my $charset = $o->get('charset');
$charset = $charset
? do {
eval { require Encode }
or (PTDEBUG &&
_d("Couldn't load Encode: ", $EVAL_ERROR,
"Going to try using the charset ",
"passed in without checking it."));
# No need to punish a user if they did their
# homework and passed in an official charset,
# rather than an alias.
":" . defined &Encode::resolve_alias
? Encode::resolve_alias($charset)
: $charset;
}
: '';
$archive_fh = IO::File->new($archive_file, ">>$charset")
or die "Cannot open $charset $archive_file: $OS_ERROR\n";
$archive_fh->autoflush(1) unless $o->get('buffer');
if ( $need_hdr ) {
print $archive_fh '', escape(\@sel_cols), "\n"