There must be a better (read shorter) way to do what I did. In the
"teach yourself perl" book (I'm trying to learn) there is an activity
as follows:
Write a short program that does the following:
-Opens a file
-Reads all the lines into an array
-Extracts all the words from each line
-Finds al words that have at least four consecutive consonants (ex:
thoughts or yardstick)
My solution is:
#!/usr/bin/perl -w
open(LINES, "act6") || die "Can't open the file act6: $!";
@lines=<LINES>;
close(LINES);
foreach $singleline (@lines) {
chomp $singleline;
@words=split(/ /, $singleline);
foreach $singleword (@words) {
$singleword=~s/\.//;
if ($singleword=~m/[^aeiou]{4,}/i) {
print "One of the words is: $singleword\n";
}
}
}
With the file "act6" containing only the following 3 lines:
This is a test file.
There are only two words that meet the match.
Those words are thoughts and yardstick.
The above works, but it sure seems like a lot of effort to simply
pull the individual words out of each line!
Thanks in advance-
Scott
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>