mashficool has asked for the wisdom of the Perl Monks concerning the following question:

Dear freinds,

Please let me know if anyone can give me that one line code that I need to put in my perl program that will really help me with my school homework.

I am very new to perl and struggling to write this simple program.

I have to write a CGI program that, given a user-specified search string, finds all words
(based on my /usr/share/dict/words file) that match this search string.


For example if I type " AN " in the search panel, the program will show me the related words from the dict file:

ANomaly

ANatomy

ANonymously

If I type "JAN" in the search panel, the program will show me:

JANuary

JANet

JANmiller

and so on ..

So far I came up with these set of codes:

$search='an'; open(W,"/usr/share/dict/words); while (<W>) { print if m/$search/; }

but it only searches for "an". What if I want to search for any word ?? What would the search string be ?

Help please

------------------------------------------------

Please help me. Regards, Mash

Replies are listed 'Best First'.
Re: Need Simple Perl Help plz
by Joost (Canon) on Jun 12, 2006 at 22:33 UTC
Re: Need Simple Perl Help plz
by ikegami (Patriarch) on Jun 12, 2006 at 22:34 UTC

    Sorry, I misunderstood the question. I thought the OP was saying he was only getting the word "an" returned.

    Works for me, as it should.

    Aani abaisance abandon abandonable abandoned abandonedly abandonee ... zygobranchiate zygopteran zygosporange zygosporangium Zyrenian Zyrian Zyryan

    You'll need to add the missing quote first, of course. And you'd profit from making the search case-insensitive: print if m/$search/i;

    As an aside, please enclose your code in <c>...</c> tags.

Re: Need Simple Perl Help plz
by merlyn (Sage) on Jun 12, 2006 at 23:14 UTC
      perlbot, be mashficool
      --
      jpg