logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Data::Random::WordList - Perl module to get random words from a word list

Author

       Originally written by: Adekunle Olonoh

       Currently maintained by: Buddy Burden (barefoot@cpan.org), starting with version 0.06

Description

       Data::Random::WordList is a module that manages a file containing a list of words.

       The module expects each line of the word list file to contain only one word.  It could thus be easily
       used to select random lines from a file, but for coherency's sake, I'll keep referring to each line as a
       word.

       The module uses a persistent filehandle so that there isn't a lot of overhead every time you want to
       fetch a list of random words.  However, it's much more efficient to grab multiple words at a time than it
       is to fetch one word at a time multiple times.

       The module also refrains from reading the whole file into memory, so it can be safer to use with larger
       files.

Methods

new()
       Returns a reference to a new Data::Random::WordList object.  Use the "wordlist" param to initialize the
       object:

       •   wordlist  -  the  path to the wordlist file.  If a path isn't supplied, the wordlist distributed with
           this module is used.

   get_words([NUM])
       NUM contains the number of words you want from the wordlist.  NUM defaults to 1 if  it's  not  specified.
       get_words()  dies  if  NUM is greater than the number of words in the wordlist.  This function returns an
       array or an array reference depending on the context in which it's called.

   close()
       Closes the filehandle associated with the word list.  It's good practice to do  this  every  time  you're
       done with the word list.

Name

       Data::Random::WordList - Perl module to get random words from a word list

See Also

       Data::Random

perl v5.26.2                                       2018-07-20                        Data::Random::WordList(3pm)

Synopsis

         use Data::Random::WordList;

         my $wl = new Data::Random::WordList( wordlist => '/usr/share/dict/words' );

         my @rand_words = $wl->get_words(10);

         $wl->close();

Version

       0.12

See Also