Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression program doesn't print

Tags:

regex

perl

I am trying to read data from a file and print the words (one per line) that contain all of the lowercase vowels ('a', 'e', 'i', 'o', 'u') in order. they don't need to be next to each other

#!/usr/local/bin/perl
#$data_file = "words.txt;
open (MYFILE, $data_file) or die "can't find file - $!";

while (<MYFILE> =~ m/.*a.*e.*i.*o.*u.*/i)
{
    print "$_";
}

close(MYFILE);

it is not printing anything :/

like image 399
codeeeeeNOT Avatar asked Aug 13 '26 03:08

codeeeeeNOT


1 Answers

The problem isn't the regular expression, but how you use the file handle, try this:

while (<MYFILE>) {
    print if /.*a.*e.*i.*o.*u.*/i;
}
like image 123
Alec Avatar answered Aug 15 '26 16:08

Alec



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!