O script a seguir é simples mas muito útil.
O objetivo é converter a codificação de arquivos (de ISO-8859-1 para UTF-8, por exemplo) em um determinado diretório.
#!/usr/bin/perl
use strict;
use warnings;#—- lista de extensões que devem ser convertidas
my @converter = qw(
tt
xml
sh
t
sql
cgi
yml
js
pm
pod
css
txt
htm
html
pl
conf
PL
);my @lista = qx’find|grep -v .svn’;
chomp @lista;foreach my $item (@lista) {
if (-f $item) {
my @arq = split(/(\|/)/, $item);
my $arquivo = $arq[$#arq];my @nome = split(/./, $arq[$#arq]);
my $ext = $nome[$#nome];my $found = 0;
foreach (@converter) {
if ($_ eq $ext) {
$found = 1;
}
}if ($found) {
my $temp = $item.’.utf8′;
system(qq|iconv –from-code=ISO-8859-1 –to-code=UTF-8 $item > $temp|);
system(qq|mv $temp $item|);
}
}
}
exit;
Deixe um comentário