If you're seeking words which contain three
different vowels (a possibility which is neither ruled-in nor ruled-out by your initial post), this is one of many ways to do so:
#!/usr/bin/perl
use strict;
use warnings;
# cf pl_test/751890.pl
my @myarray=qw/two three threee fouuuuur five septigesimal sodium hexa
+flouride/;
my @vowels=qw/a e i o u/;
my @words_having_3_vowels;
for my $var(@myarray) {
my $seen;
for my $vowel(@vowels) {
if ($var =~ m/$vowel/) {
$seen++;
if ($seen == 3) {
push @words_having_3_vowels, $var;
next;
}
}
}
}
for my $words(@words_having_3_vowels) {
print "$words \n";
}
=head execution output:
pl_test/751890_a.pl
septigesimal
sodium
hexaflouride
=cut
Now, echoing responses above, please read about <code>...</code> (or <c>...</c> tags in Writeup Formatting Tips or Markup in the Monastery so that your code is readable (what you did is, but more complex code, or that using characters like [ would NOT be readable without code tags.
And read also How do I post a question effectively? because "But not getting the expected results." is not a description of the problem which clarifies your problem. Also, as noted above, your description of what you're trying to achieve is ambiguous./p>
Finally, the original code, cleaned up to use strict; and use warnings;; with variables declared (albeit, not constrained as to scope with appropriate indentation (well, one legible version of 'appropriate' indentation, of which there are many);
#!/usr/bin/perl
use strict;
use warnings;
my @myarray=qw/two three threee fouuuuur five septigesimal/;
my @vowels=qw/a e i o u/;
my @words_having_3_vowels;
foreach(@myarray) {
my $var=$_;
for ( my $p=0; $p<5 ; $p++ ) {
for ( my $q=0; $q<5 ; $q++ ) {
for ( my $r=0; $r<5 ; $r++ ) {
if ( $var =~ /^(.*)($vowels[$p])(.*)$vowels[$q](.*)$vo
+wels[$r](.*)$/ ) {
push @words_having_3_vowels, $var;
}
}
}
}
}
for my $result(@words_having_3_vowels) {
print "|$result|\n";
}
=head execution output:
|threee|
|fouuuuur|
|fouuuuur|
|septigesimal|
|septigesimal|
|septigesimal|
|septigesimal|
|septigesimal|
|septigesimal|
|septigesimal|
|septigesimal|
=cut
This is unnecessarily hard on you and the future reader and could be avoided by <insert> either of</insert> the technique ikegami cites; it's also far more work to type (and track) than linuxer's solution. Note, however, that his output is a per-word vowel count; not the words with 3 or more vowels, and also that lines 20-22 in my "cleaned up" version change your print command (line 16 by my count) to a print-in-a-loop that prints a word (wrong: each time its vowel-count exceeds two) (correction: one or more times for reasons I'm too lazy to explore and elucidate).
Update Inserted the italicized clarification re ikegami's suggestions.
update 2 Original statement re output, now stricken, is incorrect.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.