counting paragraphs in text file

Posted by robjez on Stack Overflow See other posts from Stack Overflow or by robjez
Published on 2010-03-14T19:14:45Z Indexed on 2010/03/14 19:25 UTC
Read the original article Hit count: 206

Filed under:

I need to create perl code which allows counting paragraphs in text files. I tried this and doesn't work:

open(READFILE, "<$filename")
or die "could not open file \"$filename\":$!";

$paragraphs = 0;

my($c);

while($c = getc(READFILE))
{
if($C ne"\n")
{
$paragraphs++;
}
}

close(READFILE);

print("Paragraphs: $paragraphs\n");

© Stack Overflow or respective owner

Related posts about perl