2017-01-26 3 views
0

"L2seq1.txt"の行数と文字数を取得するために、次のループを変更するように私に依頼している学校の割り当てに取り掛かっています。これを行うには、 chompを含んでいます。 しかし私はこれで非常に新しいといくつかのトラブルがあるので、私は非常にあなたの助けに感謝します。 ありがとうございました!whileループでlength関数を使用するにはどうすればよいですか? (Perl)

open(SEQ, "<", "L2seq1.txt") or die; 
while (my $line = <SEQ>) { 
print $line; 
} 
close SEQ or die; 
+1

http://perldoc.perl.org/functions/length.html – delicateLatticeworkFever

+5

あなたはムシャムシャ食べるが、それを削除しますので、改行文字は、「文字」であるかどうか、あなたの先生と明確にあります... –

答えて

1
#!/usr/bin/env perl 
use strict; 
use warnings; 

my ($length_with_nl, $length_without); 
open my $seq, '<', "L2seq1.txt" or die "could not open L2seq1.txt: $!\n"; 
while (readline $seq) { 
    $length_with_nl += length; 
    chomp; 
    $length_without += length; 
} 
my $lines = $.; 
close $seq; 
print "lines $lines lwn $length_with_nl lwout $length_without\n"; 
関連する問題