CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Finding vowels

 



paragkalra
Novice


Mar 19, 2009, 2:43 PM

Post #1 of 2 (2198 views)
Finding vowels Can't Post

I want to find words containing at least 3 vowels. This is what I am trying:

#!/usr/bin/perl
@myarray=qw/......it contain words..../;
@vowels=qw/a e i o u/;
foreach(@myarray) {
$var=$_;
for ( $p=0; $p<5 ; $p++ ) {
for ( $q=0; $q<5 ; $q++ ) {
for ( $r=0; $r<5 ; $r++ ) {
if ( $var =~ /^(.*)($vowels[$p])(.*)$vowels[$q](.*)$vowels[$r](.*)$/ ) {
push @words_having_3_vowels, $var;

}
}
}
}
}
print "@words_having_3_vowels \n";

But not getting the expected results.
Parag.A.Kalra, The Linux Man
http://www.paragkalra.com/
In this world without WALLS and GATES who need WINDOWS! USE LINUX! STOP PIRACY! GO OPEN SOURCE!


KevinR
Veteran


Mar 19, 2009, 3:53 PM

Post #2 of 2 (2195 views)
Re: [paragkalra] Finding vowels [In reply to] Can't Post

If this is school work, based on the code you been posting, your teacher/instructor/professor will probably know you did not come up with this soultion:


Code
#!/usr/bin/perl 
use strict;
use warnings;
my @myarray = qw/Fee fie foe fum I smell the blood of an Englishman/;
my @matches;
foreach (@myarray) {
if (tr/aeiouAEIOU/aeiouAEIOU/ >= 3 ) {
push @matches,$_;
}
}
print "$_\n" for @matches;


The above is just a version of the code in the perl faqs:

http://perldoc.perl.org/perlfaq4.html#How-can-I-count-the-number-of-occurrences-of-a-substring-within-a-string%3f
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives