Welcome to the Monastery. I've upvoted your post because you have made an effort to write some code and also do some research; don't worry too much about the downvotes as formatting faux pas often receive a negative reaction. Please don't let this put you off the Monastery, keep visiting as it is a great learning resource.
Other Monks have given good advice and have covered the most important points. I would just like to draw your attention to a couple of further glitches.
- A minor point, you have forgotten to say what you are counting in the last two lines of your output :-)
- More seriously, your logic for counting paragraphs will fail if you have a trailing empty line (or lines) at the end of your data file. You should also consider how you wish to treat lines that just contain spaces and also multiple blank lines between paragraphs.
I hope these thoughts are helpful.
Cheers,
JohnGG
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.