# 读写文件. #/usr/bin/perl -w use 5.010; # Use 'say'.
# Read from file. open F, "<data.txt" or die "fail: open()"; my @arr = <F>; # Read all data to array. close F;
# Write to file. open F, ">res.txt" # Use ">>" if you want to append at end. or die "fail: open()"; while (@arr) { print F ($_."\n"); # Write to file. } close F;
# 将单词首字母大写, 其它字母小写 $_="walfud ranisic durk" ; s/(\b\w+\b)/\u\L$1\E/g ;
print ;
# 批量改名 foreachmy$name (glob"*.old") { my$newName=$name ; $newName=~ s/\.old$/\.new/ ;
if (-e $newName) { warn"can't rename '$name' to '$newName': $newName exists"."\n" ; } else { rename$name,$newName or warn"rename '$name' to '$newName' failed: $!"."\n" ; } }
# 将长整数每三位以 ',' 分隔 my$number="1234567890123" ; 1while$number=~ s/^(-?\d+)(\d\d\d)/$1,$2/ ;
print$number ;
|
请发表评论