文件夹中以下内容:
com.sohu.www
cn.com.sina.www
com.163.www
com.qq
以上内容变为:
www.sohu.com
www.sina.com.cn
www.163.com
qq.com
Perl代码如下:(perl处理domain.txt,输出结果到domain_re.txt中)
my $sucess_read = open domain,"domain.txt";
if (!$sucess_read){
die "失败";
}
open LOGF,">","domain_re.txt"||die "$!";
while(<domain>){
chomp($_);
@array = split /\./,$_; #逗号需要转义
@array_re = reverse @array;
$result = join ".",@array_re;
print LOGF $result;
print LOGF "\n";
}
close(domain);
close LOGF; #不关闭该句柄话写不到文件中