Advertisement
dougllio

vwc.pl

Jul 20th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.79 KB | None | 0 0
  1. ####################################
  2. # Vowel counting alternate solution
  3. ####################################
  4.  
  5. print "Counting vowels in this sentence: ";
  6.  
  7. # Get input from STDIN
  8. $sentence = <>;
  9.  
  10. # Split sentence into an array of words
  11. @splitsentence = split /\s/,$sentence;
  12.  
  13. # Loop through for each vowel
  14. for $vowel ("a", "e", "i", "o", "u", "y") {
  15.  
  16.   # Use grep to count the number of matches and return the number of matches
  17.   # the function will do both based on the variable used to get the return
  18.   # value of the function
  19.   $count = grep /$vowel/, @splitsentence;
  20.   @matches = grep /$vowel/, @splitsentence;
  21.  
  22.   # Print out the results for this trip through the vowel loop
  23.   print "\nWords with $vowel: $count - " . join ", ",@matches;
  24. }
  25.  
  26. # Spacer
  27. print "\n\nHit ENTER ";
  28. <>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement