Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################
- # Vowel counting alternate solution
- ####################################
- print "Counting vowels in this sentence: ";
- # Get input from STDIN
- $sentence = <>;
- # Split sentence into an array of words
- @splitsentence = split /\s/,$sentence;
- # Loop through for each vowel
- for $vowel ("a", "e", "i", "o", "u", "y") {
- # Use grep to count the number of matches and return the number of matches
- # the function will do both based on the variable used to get the return
- # value of the function
- $count = grep /$vowel/, @splitsentence;
- @matches = grep /$vowel/, @splitsentence;
- # Print out the results for this trip through the vowel loop
- print "\nWords with $vowel: $count - " . join ", ",@matches;
- }
- # Spacer
- print "\n\nHit ENTER ";
- <>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement