re: Daily Challenge #3 - Vowel Counter VIEW POST

FULL DISCUSSION
 

This is very easy in Perl, as the transliteration operator returns the number of matches:

sub vowel_count2 { shift =~ tr/aeiouAEIOU// }

One can also use the Saturn (or Goatse) "secret" operator with a regex match:

sub vowel_count { my $count =()= shift =~ /[aeiou]/gi }

The global match returns all the matches in list context, the assignment to () enforces list context, and enforcing scalar context on it by a scalar assignment returns the number of elements.

code of conduct - report abuse