Re your question, "Is there a code for carriage returns?"
Yes, \n,
That's pretty basic but...
- Whether or how a carriage return defines a paragraph, in a grammatical sense is another question. Some definitions of a paragraph construe the combination of a period followed by a carriage return and a second <CR> in the next, otherwise empty line as a paragraph indicator. But others might consider any line beginning with indentation (eg, leading space(s) or tab) greater than that of the previous line as a paragraph indicator... and if you wish to stretch a bit, some plain text might invite the interpretation that any <CR> marks a paragraph end. How are you defining a paragraph?
- Similarly, your test for sentences,
if ($ch eq "?" || $ch eq "!" || $ch eq ".")
is incomplete because it fails to allow for the possibility that the sentence may contain an abbreviated word or words:
"Mr. John Doe, Jr. is a Sr. programmer for E.H.I., Inc. Miss Laura J. Smith is a Analyst for ABC. "
How many sentences are there? By inspection, I'm sure you'll agree, there are two. But your test for sentences will give you a much higher sentence count.
As to the rest of your logic and syntax: Note that your code won't compile (running perl -c yourcode is a good idea before posting :-) as is (if this is the problem) double-checking that what you've posted matches what your thouight you posted. Even with all the syntactical issues fixed, I can't make your code extract the values you assert you've obtained.
Regretably, I've run out of time and ambition to identify/clarify/correct all of those, but they're issues of higher precedence than your hope to do all the counting in a single while clause. At this point, I have to suspect that producing this relied as much on cutting and pasting snippets from hither and yon, as on study and comprehension. Note however, that among other things, you're trying to use getc on a filehandle that isn't open; that the use you would be making of getc if the filehandle were open would be redundant (you've already read all the chars; why not read them from $filecontents?) and .../me trails off in dismay....)
Perhaps you'll get some inspiration from the Perl Cookbook (for instance chapter 8, and 8.2 especially).
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.