有文本a.txt如下:
aaaaaaa aaaa bbbbbb ccccccccccc dddd
aa aaaaaaa bbbbbbbb cccccccccc ddddddddddddd eeeeeee
aaaaaaaaaaaa bbbbbbbbbbb cccccccccccccccccccc
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aa
aaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbb
aaaaaaaaa ccccccccc bbbbbbbbbbbbb ddddddddddddddddd
通过批处理查找出文本中字符数(不含空格)最多的行并输出,很明显就是复制内容到剪贴板代码:
aaaaaaaaa ccccccccc bbbbbbbbbbbbb ddddddddddddddddd- my $max=0;
- my $max_length;
- open(FH,"<","a.txt") or die;
- while (<FH>) {
- chomp;
- my $num=tr/ //c;
- $max=$num and $max_length=$_ if $num > $max;
- }
- print $max_length;
复制代码
|