Subject: a recursion perl script
To: None <netbsd-users@NetBSD.org>
From: Water NB <netbsd78@126.com>
List: netbsd-users
Date: 09/06/2006 01:57:32
I wrote below perl script to convert all files and directories.
When it enter the first directory, the script quit and skip any others
directories without any errors.
What's wrong?
#! /usr/pkg/bin/perl
use Unicode::UTF8simple;
use Cwd;
my $uref = new Unicode::UTF8simple;
my $dirname = shift;
sub g2u {
my ($dirname) = @_;
my $g, $u, @D;
printf "----> $dirname\n";
opendir(DIR, $dirname) || die "can't opendir $dirname: $!";
@D = readdir(DIR);
foreach $g (@D) {
#printf "file $g\n";
if ( -d $g && $g ne "." && $g ne "..") {
#printf "----> $g\n";
&g2u("$dirname/$g");
}
my $u = $uref->toUTF8("gb2312", $g);
if ($g ne $u) {
printf "GB2312==>UTF8 $g\n";
#rename "$dirname/$g", "$dirname/$u";
}
}
closedir DIR;
}
&g2u($dirname);