# File: fileSkipLines.pl # Title: Read a text file and print it lines. Ignore some lines # Author: Mihaela Malita # use symbols: first char(^) and last char($) # Here is the file names.txt, has comment lines(lines that start with #) and empty lines # # File with names # # # Mary # John # Evan my $filename; my $line; print "Name of the file (names.txt)? "; $filename = ; chop($filename); #read from keyboard unless (open(IN,"$filename")) { #check if the file exists print "No file with such a name!"; exit; } # count only the lines with names # and skip empty lines # that is skip line with comments, first char is # $count = 0; while ($line = ) { #reads line by line the text file until End Of File (EOF) if ($line =~ m/^\s*$/) {next}; # skip empty line ^\s*$ first char(^) and last char($) if ($line =~ m/^#/ ) {next}; # skip lines with first char(^) as # # ($line =~ m/^\s*#/) match lines that start with any number of blanks followed by # # ($line =~ m/^\s*>/) match lines that start with any number of blanks followed by > print "$line"; $count++; } print "\n # lines with names is $count."; close IN; exit;