Hi,
how can I count the number of punctuation characters within a text file prompted from the keyboard?
how can I count the number of punctuation characters within a text file prompted from the keyboard?
#!/usr/bin/perl
my $inFile = $ARGV[0] or die "no file specified";
open(IN, $inFile) or die "open $inFile: $!";
my $count = 0;
while (my $line = <IN>) {
while ($line =~ m{([\.\!\?])}g) {
print "$1";
$count++;
}
}
print "\n$count punctuation characters in $inFile\n";
close(IN) or die "close $inFile: $!";
1;
__END__
Comment