Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: regex to find vowels in anyorder

by Not_a_Number (Parson)
on Dec 19, 2011 at 20:20 UTC ( #944294=note: print w/ replies, xml ) Need Help??


in reply to regex to find vowels in anyorder

I'm trying to find a regex that will...

You don't need no steenkin' regex:

open my $fh, '<', 'whatever'; # or whatever my %hash = ( a => 0, e => 1, i => 2, o => 3, u => 4 ); while ( <$fh> ) { chomp; my $copy = $_; my @array; while ( my $char = lc chop $copy ) { no warnings 'uninitialized'; $array[ $hash{ $char } ] = 1; } say if ( grep $_, @array ) == 5; }

Pretty fast, too, you'll find...

Update: Hmm, if you take out the line no warnings 'uninitialized'; (and therefore remove use warnings or whatever from the start of the code), it seems to run nearly 20% faster still...

Comments welcome.

Update 2: Oops, just realised that my code doesn't work! Change the contents of the inner while loop to:

$array[ $hash{ $char } ] = 1 if defined $hash{ $char };

Which is what I had originally, before playing with no warnings 'uninitialized';. And then I didn't test properly.

Mea culpa.


Comment on Re: regex to find vowels in anyorder
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (16)
As of 2014-09-02 14:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (24 votes), past polls