You have more problems than just this one I am afraid.

As I don't want to solve the exercise for you here is just a piece that should put you on the right tracks::

#!/usr/bin/perl -w use strict; # in addition to using -w this will # help you find more errors # if you use strict then you have to declare your variables, usually u +sing my my %count = ("para",0,"sen",0); while ( <> ) # read a record (a line here) and set $_ { # a paragraph is any line that has at least one non-space characte +r if ( /\S/ ) { $count{para}++; } # the g modifier allows you to loop through the string # matching successive occurences of the pattern while ( /[.?!]/g) { $count{sen}++; } # use s/// to substitute the pattern # \w is a word character, # $1 is the text that was matched between the () # /g does the substitution for all matches in the string # /e evaluates the right part expression lc($1) s/([aeiou]\w*)/lc($1)/eig; } # this is how you print a hash foreach my $value (keys %count) { print "$value: $count{$value}\n"; }

You should be able to finish the assignement from there. But you'd better figure out exactly what this snippet is doing and why or it might be difficult for you to answer questions from your teacher as to what goes on there.

I have a question for the regexp experts by the way, I thought you needed to backslash the . in the character class, but it seems that it works fine (matching just the dot character) without it. Is this a new behaviour (I am using 5.6.1) or was . just '.' in a character class in older versions?


In reply to Re: New perl student... feeling stupid by mirod
in thread New perl student... feeling stupid by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.