ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
There don't seem to be any modules or built-in character sets which include a comprehensive group of vowels, at least not externally. However, CPAN's Unicode::Normalize can convert to ASCII and then you can check with a pattern similar to one of the ones which you have used above.
Code:
#!/usr/bin/perl
use Unicode::Normalize;
use strict;
use warnings;
while (my $s = <>) {
if ($s =~ m/^\w{7}$/) {
my $d = NFKD($s);
if ($d =~ m/[aeiou]{1}/ && $d !~ m/[aeiou](?=.*[aeiou])/i) {
print $s;
}
}
}
exit(0);
That reads in a line and checks if it contains a seven-letter string. Then it normalizes it to ASCII and checks for the presence of a single vowel, except for y in English and w in Welsh etc.
I think that's about as short as it can be with the Unicode constraint. If you are sticking with ASCII then sed or grep would be enough.
Edit: The old version allowed up to one vowel but did not require one. The modification requires exactly one vowel.
Last edited by Turbocapitalist; 09-14-2022 at 11:18 PM.
Reason: $d =~ m/[aeiou]{1}/ && ...
you can also try to
1. filter 7 letter words,
2. remove all the non-wovels (like your sed)
3. check length again, should be 1
but the post #3 and #4 are definitely much better. I would avoid using pipe chains if possible.
Filter for words which do match [aeéiouy] in a suitable words-file, then pipe the results to keep only those which donot match [aeéiouy].*[aeéiouy]. Finally, filter out all which are not seven-letter words. (Rearrange the order of piped operations as you like.)
A "shell one-liner," given a suitable "words file," can solve this. No programming is required.
Q.E.D.
Last edited by sundialsvcs; 09-15-2022 at 12:05 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.