# Purpose: this script converts the encoding of bunch of file recursively
use Encode;
use Win32 ;
use strict ;
use warnings ;
use Cwd;
use File::Find;
my $file_pattern ='.*?html'; #in what kind of files are we interedsted
sub main
{
find(\&d, cwd);
}
sub d {
my $file = $File::Find::name;
$file =~ s,/,\\,g;
return unless -f $file;
return unless $file =~ /$file_pattern/;
local( $/, *FILE ) ;
open (FILE , $file) or
die "Cannot find $file !!! " ;
my $fileString =
close FILE ;
my $fileByteStream = decode('windows-1251', $fileString );
my $UTFSream = encode('UTF-8', $fileByteStream);
open (FILE , ">$file") or die "Cannot find $file !!! " ;
print FILE "$UTFSream" ;
close FILE ;
print $file , " converted to Windows -1251 done !! \n" ;
} #eof d
main(); #action!!!
1 ;
__END__
SOURCES:
http://search.cpan.org/~rgarcia/perl-5.9.4/pod/perlunitut.pod
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!