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

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?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2015-11-28 09:54 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls