[PLUG] Paragraph Counting Script
Eric Wilhelm
scratchcomputing at gmail.com
Mon Jul 13 22:46:57 UTC 2009
# from Rich Shepard
# on Monday 13 July 2009 15:26:
> Does anyone have a working script that will count chunks of text
> separated by two newlines?
perl -e 'local $/ = "\n\n"; my @p = <>; print scalar(@p), "\n";'
You may want to check for blank paragraphs or allow for trailing,
ending, or more than two newlines. If you don't care about the
paragraph content, just counting those conditions would be like:
1+scalar(() = $t =~ m/(?!^)(\n\n+)(?!$)/mg)'
--Eric
--
"It works better if you plug it in!"
--Sattinger's Law
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
More information about the PLUG
mailing list