Hi Linicks,

a couple of a comments to improve your code.

open (DICT, "< final.txt");
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 my $DICT, "<", "final.txt" or die "cannot open 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$!"; while (my $word = <$DICT>) { next unless $word =~ /s.*h/i; next if $word =~ /s.*s/i or $word =~ /h.*h/i; print $word; }
You could also use a series of greps to filter your data:
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>;
or possibly only one grep with a composite condition.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.