Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Finding vowels

by Marshall (Canon)
on Mar 20, 2009 at 05:33 UTC ( [id://751941]=note: print w/replies, xml ) Need Help??


in reply to Finding vowels

For the problem as stated, this is a "one line'er". The idea of tr is a good one as others have said. You don't need a foreach loop as grep is designed to filter lists. Here the number of substitutions are used in a scalar context within the grep. No changes are made to the input @array list. But you could just use @array instead of @vowelsGT2 and @array would automatically shrink.
#!/usr/bin/perl -w use strict; my @array = qw( chatterbox teste abode fooooo foo); my @vowelsGT2 = grep{ tr/aeiouAEIOU// >2}@array; print "Words with >2 vowels: @vowelsGT2\n"; __END__ prints: Words with >2 vowels: chatterbox abode fooooo

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-25 17:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found