in reply to regex testing for ALL of the vowels in a scalar

Good candidate for an OBFU. :-)

In the following example, $found is the number of unique vowels found in your string. Just test if it is equal to 5.
use strict; use warnings; my $word = "alighthousa"; my $found; if (($found = ( keys %{{map { $_ => 1 } ($word =~ m/([aeiou])/g) }} )) + == 5) { print "Found all 5 vowels\n"; } else { print "Found only $found vowels\n"; }

Ok, may be I should explain what is happenning here:

($word =~ m/([aeiou])/g) # returns a list of all vowels found in $word map { $_ => 1 } ($word =~ m/([aeiou])/g) # builds a list for initializing a hash { map { $_ => 1 } ($word =~ m/([aeiou])/g) } # a reference to an anonymous hash initialized with the list keys %{ { map { $_ => 1 } ($word =~ m/([aeiou])/g) } } # return keys of the dereferenced anonymous hash # the keys in a hash are unique, this effectively # eliminates duplicates, and gives a list of unique # vowels found in the string $found = ( keys ... ) # this assigns the number of unique vowels found into $found

Replies are listed 'Best First'.
Re^2: regex testing for ALL of the vowels in a scalar
by Anonymous Monk on Feb 11, 2004 at 05:05 UTC

    Very nice approach indeed. Just to touch up on including uppercase vowels:

    $_ = 'A Lighthouse'; if (5 == keys %{{map {lc $_ => undef} m/([aeiou])/ig}}) { print "Found at least one of each vowel.\n"; } else { print "Not all vowels were found.\n"; }