in reply to check if all certain chars are found in a sentence
Just for fun, here's a modest alternative:
which starts by scanning the sentence for any of the wanted characters, and removes each one it finds from the wanted list before scanning from where it left off.sub scan { my ($sentence, $wanted) = @_ ; while (length($wanted)) { return 0 if ($sentence !~ m/([$wanted])/g) ; $wanted =~ s/$1// ; } ; return 1 ; } ;
This may, or may not, be quicker than scanning for each wanted character individually -- indeed, that is probably quicker if you could arrange to scan for unusual characters first.
Mind you, you didn't say why you need a smarter solution. Or, indeed, what counts as smarter in this context.
|
|---|