我保存一份能够从各种来源获得其投入的文字,并按行各业。 视实际使用的来源而定,分界线可能是不一式的,视窗式的,甚至,对一些综合投入而言,是混合的(!)。
在阅读档案时,情况就是如此:
@lines = <IN>;
process(@lines);
...
sub process {
@lines = shift;
foreach my $line (@{$lines}) {
chomp $line;
#Handle line by line
}
}
So, what I need to do is replace the chomp with something that removes either Unix-style or Windows-style linebreaks. I m coming up with way too many ways of solving this, one of the usual drawbacks of Perl :)
您对如何克服一般突破的无端做法有何看法? 什么是最有效的?
Edit: 略微澄清——方法过程从某个地方获得一份线表,从上读。 每一行可能
- No trailing linebreaks
- Unix-style linebreaks
- Windows-style linebreaks
- Just Carriage-Return (when original data has Windows-style linebreaks and is read with $/ = )
- An aggregated set where lines have different styles