From: "R. Joseph Newton" <[EMAIL PROTECTED]>
> "John W. Krahn" wrote:
>
> > This is the closest but you need a separate match for each letter
> >
> > > # print $_ if /a\&e\&i\&o\&u/gi; # try a bitwise "and", with
> > > # escapes print $_ if !/[bcdfghjklmnpqrstvwxyz]/gi; # try
> > > # not matching consonants
> > > print $_ if /(a+)(e+)(i+)(o+)(u+)/gi; # "LOTS of
> > > parentheses"
> >
> > By default print() prints the contents of $_ if there are no
> > arguments so "print if ..." does the same thing. Also none of your
> > matches require the /g option.
> >
> > > }
> > >
> > > AAAAAAAARRRRRRRRRRGGGGGGGGGGGGHHHHHHHHH!!!!!!!!!
> >
> > Fun, isn't it? :-)
>
> Hi John,
>
> I think this is one that sort of defeats the one-liner, or at least
> the single regex:
>
> But oh, I get mad!
>
> if (/a/i and /e/i and /i/i and /o/i and /u/i) {print;}
It might be quicker if you do some work before trying the regexps:
while (<>) {
chomp;
print "\tOK ($_)\n"
if do {(local $_ = lc($_)) =~ tr/aeiou//dc;
/a/ and /e/ and /i/ and /o/ and /u/
}
}
This looks strange mainly due to the fact that I use $_ everywhere.
If I used an ordinary variable in the loop it could look like this:
while ($line = <>) {
chomp($line);
local $_ = lc($_);
tr/aeiou//dc;
print "\tOK ($line)\n"
if (/a/ and /e/ and /i/ and /o/ and /u/);
}
Basicaly all I do is I copy the string lowercased into another
variable, remove all characters except the aeiou and then test the
regexps agains that much shorter string.
If I add a length test (string of 4 characters cannot contain all
five we search for) I can make it even quicker:
while (<>) {
chomp;
print "\tOK ($_)\n"
if do {(local $_ = lc($_)) =~ tr/aeiou//dc;
length($_) >=5 and /a/ and /e/ and /i/ and /o/ and /u/
}
}
or
while ($line = <>) {
chomp($line);
local $_ = lc($_);
tr/aeiou//dc;
print "\tOK ($line)\n"
if (length($_) >=5 and /a/ and /e/ and /i/ and /o/ and /u/);
}
Benchmarking is left to the reader as a simple homework.
Jenda
P.S.: What about "Y" ?
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]