G+_Darryl Medley Posted July 2, 2014 Share Posted July 2, 2014 Perl Vowel-Word Counter. https://github.com/Darryl-Medley/Coding-101/blob/master/VowelWordCounter.pl This is a little regex demo that counts the number of words containing each vowel (# of words with "a", # of words with "e", etc.) in a user-entered sentence. It shows two valuable regex techniques: 1. using a regex with "while" to count things, and, 2. Programatically building a regex in a string variable at run time and using it. The program shows two methods to do the count. The first is easy to understand straight-line code with a regex for each vowel and the second is a trickier but shorter routine that loops for each vowel. https://github.com/Darryl-Medley/Coding-101/blob/master/VowelWordCounter.pl Link to comment Share on other sites More sharing options...
G+_Rudy Rodriguez Posted July 2, 2014 Share Posted July 2, 2014 Works great. I'm guessing the second method is more efficient. Link to comment Share on other sites More sharing options...
G+_Darryl Medley Posted July 3, 2014 Author Share Posted July 3, 2014 I'm sure the straight-line code runs faster because there's less processing involved but the loop is more flexible so it's probably what I'd use in a real program. It all depends on what your priorities are. In a time-critical routine I'd use the straight-line code. Link to comment Share on other sites More sharing options...
G+_Shannon Morse Posted July 10, 2014 Share Posted July 10, 2014 Looks good! I'll share it on the show. Thanks! Link to comment Share on other sites More sharing options...
G+_L I Posted July 20, 2014 Share Posted July 20, 2014 An alternative solution: http://pastebin.com/5Ppdez6L Link to comment Share on other sites More sharing options...
Recommended Posts