in reply to Re: will this random-text script work? how do i integrate a template?
in thread will this random-text script work? how do i integrate a template?

You should start your script with a use File::Random qw/:all/;

This will load the File::Random module and make all of its subroutines available in your script.

Then you can do something like:

my $dir = '//path/to/my/SpamQuoteFilesDirectory'; my $file = random_file(-dir => $dir); my @lines = random_line($fname, int(rand(5)) + 1);
This script will choose at random 1 file out of all the files in your '//path/to/my/SpamQuoteFilesDirectory' and from this file choose at random 1 to 5 lines and store them in the array @lines.

BTW, you did install File::Random first didn't you?

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^3: will this random-text script work? how do i integrate a template?
by Anonymous Monk on Jan 16, 2007 at 15:57 UTC
    Thank you! And one more question -- hopefully the last: I've put File::Random and Want in a directory within the home directory of my hosting account, per related advice given here.

    What's confusing me are these instructions at CPAN, about running the Makefile.Pl, and additionally the reference in the Dreamhost link above about the "use lib" command. I've tried to research all this myself, but I think I don't know enough about programming to figure it out.

    Where/how do I need to take these final steps, so my script knows where to find the modules?

      Okay -- I think I've figured out the  use lib thing.

      Is this right?

      #!/usr/bin/perl –Tw use strict; use CGI ':standard'; use lib qw("/perl_modules"); use File::Random qw/:all/; my $dir = '//spam_oracle/infinity'; my $file = random_file(-dir => $dir); my @lines = random_line($fname, int(rand(5)) + 1);

      Specifically, will the script know to drill down within the perl_modules directory, if the modules are within subdirectories?

      And is that the correct path, if the script itself is in a cgi-bin within a subdomain on my account (mact.jesskilby.com/cgi-bin/oracle.pl)?

        As use lib qw(...) is (more or less) the same as adding your directory to the @INC array, it will drill down into this directory, just as if your directory was part of the normal Perl module tree. This means that you have to set up your private module directory in a similar way as Perl's.

        For instance: for File::Random you should place the file Random.pm inside a File directory, directly underneath your /perl_modules directory.

        Normally you should let the CPAN-module (or CPANPLUS-module) take care of this. Have a look at question 5 in the FAQ included in the CPAN-module documentation. It will explain how to set up CPAN so it installs in your private module directory.

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law