in reply to New perl student... feeling stupid
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: New perl student... feeling stupid
by runrig (Abbot) on May 18, 2001 at 23:28 UTC | |
|
Re: Re: New perl student... feeling stupid
by chipmunk (Parson) on May 18, 2001 at 23:30 UTC |