Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: regex to find vowels in anyorder

by Not_a_Number (Prior)
on Dec 19, 2011 at 20:20 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-20 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found