hi, i need to output the number of sentences in a file. The file looks like this:
For the eyeing of my scars, there is a charge,
For the hearing of my heart,
It really goes.
And there is a charge a very large charge,
For a word or a touch,
Or a bit of blood.
As you can see 6 sentences.
The perl code i have written for this is as follows:
open(OUT, "<$file") || die "Cant open $file: $!";
$sentences = 0;
my($ch);
while($ch = getc(OUT))
{
if($ch eq"?" || $ch eq "!" || $ch eq ".")
{
$sentences++;
}
}
close(OUT);
print("Statistics for $file\n");
print("Sentences: $sentences\n");
For this, sentences can either end with ?/!or . which is the reason i have them in the code. The output for the code, however says
Sentences: 0
which of course is wrong, im missing something but what!! also i need some pointers on counting characters and words coz im struggling to find resources that are helpful to me
thanx