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

I am fairly new to perl scripting and to this group! I would like to create a list of keywords using which I would process the input text. Is it sensible to create a library (or package) of such keywords and include it in script? If so, can anybody give a brief explanation of how to do it? Thanx much, Badhri

Replies are listed 'Best First'.
Re: Re:Creating Keywords!
by shemp (Deacon) on Jul 28, 2003 at 19:56 UTC
    If what you want is a list of words that could be easily re-used among a lot of projects you could create a function that would return your list, however you want it. Put the function in a required library, and require it in any program that needs it. For instance the file could look like this:
    #!/usr/bin/perl -w use strict; sub seven_dwarves_names { return qw(sleepy happy grumpy dopey sneezy bashful doc); } 1;
    Assuming that file is called keywords.pl, and is in the @INC path, a program that uses them could look like:
    #!/usr/bin/perl -w use strict; require "keywords.pl"; ... my @dwarves = seven_dwarves_names(); ...
    Of course you may want your keywords in a different manner, such as hash keys or something else. Have the shared function return the data however you want!
Re: Re:Creating Keywords!
by sauoq (Abbot) on Jul 28, 2003 at 19:59 UTC
Re: Re:Creating Keywords!
by Grygonos (Chaplain) on Jul 28, 2003 at 20:06 UTC
    edit:shemp is absolutely correct... I didn't know you could do that. It is probably the best way to pull off what you want

    your questions isn't 100% clear, but I think I understand your intentions

    IHMO, the only way that making a package would be sensible, is if you were going to be using the same keyword list in multiple scripts, and there are a large amount of keywords

    doing the following:
    #package file package myKeywords; @list_of_words = qw(my list of words);

    #User script use myKeywords; map {print $_ ."\n"} @myKeywords::list_of_words;
    Would probably produce the result you wanted(minus your text processing)
    To make a package(very rough pls no flames)
    • name your package with the .pm extension
    • Secondly.You will need a makefile.
      use ExtUtils::MakeMaker; WriteMakefile('NAME' => 'myKeywords');
      may do the trick for the simple package above.
    • You then need to run make/nmake from the same directory that your .pm file is in
      perl makefile.pl make make test
    • ..if your "make test" command is successful
      make install
      Well, I guess I found a better and easier way to get around my initial hiccups without having to make a package or library. But I sure have learnt something from your replies for my unclear question! Thanx a lot Badhri
Re: Re:Creating Keywords!
by cleverett (Friar) on Jul 28, 2003 at 19:52 UTC
    Your question isn't very clear to me. Why don't you give an example of the input and the output?