|||
众口难调。
简单个分行符,各个操作系统都个不相同。Windows: "rn", Unix: "n" Old version of Mac: "r".
写个程序要让各个系统都适用,也挺折腾。
## 小文件可以这样,都读进来,再拆分
local $/ = undef;
my $content = <DESIGN>;
my @lines = split /\r\n|\n|\r/, $content;
## 大文件,先判断系统,会省一些资源
my $osname = $^O;
local $/ = "\n";
if(uc($osname )=~ m/MSWIN/){
local $/ = "rn";
}
写个小程序,打算能使用于多些系统,来来回回也花了不少时间。
很多事情都是这样,要么不做,要么就做好。
都要做好,都要花时间,干吗不去做一些更重要的工作呢。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-16 14:29
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社