Created
October 21, 2018 13:05
-
-
Save Bas-Man/bfddb506b932693e7da2e6c4e7ec3464 to your computer and use it in GitHub Desktop.
Quick subroutine to return the number of vowels in a string. returns -1 if the string is not an ascii string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub asciiVowelCount { | |
my $str = shift; | |
# return error since this is not ascii character set | |
return -1 if $str =~ /[^[:ascii:]]/; | |
my $count = 0; | |
# Loop over each chracter in $str and increment counter if it is a vowel | |
for my $char (split //, $str) { | |
$count++ if $char =~ m/[aiueo]/; | |
} | |
return $count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment