Reputation: 9
I'm just working on a school assignment which is asking me to modify the following loop in order to get the number of lines and characters in "L2seq1.txt" I'm supposed to do this by using the length function and also include chomp. I am however very new at this and having some trouble so I would greatly appreciate your help. Thank you!
open(SEQ, "<", "L2seq1.txt") or die;
while (my $line = <SEQ>) {
print $line;
}
close SEQ or die;
Upvotes: 0
Views: 111
Reputation: 676
#!/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";
Upvotes: 1