a couple of a comments to improve your code.
Good practices nowadays recommend to use lexical file handles and the three-argument syntax for the open built-in function (and also to check that open succeeded):open (DICT, "< final.txt");
Second, if your file is large, it is a waste of resources (memory, CPU cycles and time) to store its contents into an array and then process the array, whereas you could just process directly the lines obtained from the file (unless you want to make several other searches on the same data):open my $DICT, "<", "final.txt" or die "cannot open final.txt$!";
You could also use a series of greps to filter your data:open my $DICT, "<", "final.txt" or die "cannot open final.txt$!"; while (my $word = <$DICT>) { next unless $word =~ /s.*h/i; next if $word =~ /s.*s/i or $word =~ /h.*h/i; print $word; }
or possibly only one grep with a composite condition.open my $DICT, "<", "final.txt" or die "cannot open final.txt$!"; print for grep { not /h.*h/i } grep { not /s.*s/i } grep /s.*h/i, <$D +ICT>;
Update: fixed the typo mentioned by Linicks: s/~=/=~/;.
In reply to Re^3: Dictionary filter regex
by Laurent_R
in thread Dictionary filter regex
by Linicks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |