下載的zip包解壓後,中文都變成了亂碼,就寫了個腳本重命名文件。spa
use strict; use warnings; use Cwd; sub main { my $dir = getcwd(); opendir my $DH, $dir or die "Can not open directory: $dir"; while (my $file = readdir $DH) { if ($file =~ /.*-(\d{3})_.*\.mp3$/) { rename $file, "$1.mp3"; } } } main()
Perl中獲取當前目錄有兩種方法:code
user Cwd; my $dir = getcwd;
或者blog
my $dir = $ENV{'PWD'};
前者的好處是跨平臺。後者的好處是不用引入額外的包,可是Windows上不能用。ip
==get