Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: regex to find vowels in anyorder

by pvaldes (Chaplain)
on Dec 19, 2011 at 15:46 UTC ( #944267=note: print w/replies, xml ) Need Help??


in reply to regex to find vowels in anyorder

Nested notation and uppercase

if (/a/i){ if(/e/i){ if(/i/i){ if(/o/i){ if(/u/i){ print "we found the five vowels"; } } } } }

Replies are listed 'Best First'.
Re^2: regex to find vowels in anyorder
by Marshall (Canon) on Dec 19, 2011 at 16:06 UTC
    I think BrowserUk's solution is going to be faster. But past that I would not use nested if's when you mean "and" or "&&". Get rid of 4 unnecessary levels of indentation.
      I think BrowserUk's solution is going to be faster.
      That would not be my guess, unless it's the /i that's killing the performance. /a/ will not use the regexp engine, the optimizer will do it. If speed is an issue, and you want to be case sensitive, my bet would go to:
      if ((/a/ || /A/) && (/e/ || /E/) && (/i/ || /I/) && (/o/ || /O/) && (/ +u/ || /U/)) { ... }
      but I'm too lazy to come up with a good benchmark (which should test for both match and non-match). And if the query set would be English words, I'd order the vowels from least frequently occurring to most frequently (probably u-i-o-a-e, but I'd have to look that up), in order to fail faster.

      Of course, it's also very likely speed doesn't matter at all.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://944267]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2021-10-24 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?