Random_Entry

Random_Entry returns a random entry from a structured file.

It can be used for things such as random quote files to add dynamic content to a web page and can be called as a server-side include (SSI) or as a CGI.

There are two parameters that may be passed to it in the query string. 'f' is required.
f
Full path to file. File name MUST end in ".random.txt"
s
The separator used to separate entries in the file. If none is specified, the separator is a newline (entries are one line each). If left blank, (e.g. "&s="), the separator is two or more consecutive newlines. Any string of characters may be specified, but they must be properly URL-percent-encoded in the query string (&s=...).

Examples

    <!--#set var="data_file"
             value="/pub/m/y/myacct/homepage/quotes.random.txt"-->
    <!--#include
             virtual="/cgi-bin/utils/randomentry?f=$data_file"-->
These can be put on a single "#include virtual=..." line, but the above is neater.
If entries are separated by blank lines ("\n\n", e.g.
  my entry
  has multiple lines

  my next entry
  does, too
then the SSI would look something like
    <!--#set var="data_file"
             value="/pub/m/y/myacct/homepage/quotes.random.txt"-->
    <!--#set var="separator"
             value="%0A%0A"-->
    <!--#include
             virtual="/cgi-bin/utils/randomentry?f=$data_file&s=$separator"-->
If the separator is "\n\n--\n\n", as in
  my entry

  has multiple lines

  with blank lines inbetween

  --

  my next entry

  continues in the same fashion
then the SSI would look something like
    <!--#set var="data_file"
             value="/pub/m/y/myacct/homepage/quotes.random.txt"-->
    <!--#set var="separator"
             value="%0A%0A--%0A%0A"-->
    <!--#include
             virtual="/cgi-bin/utils/randomentry?f=$data_file&s=$separator"-->


Random_Entry is a Perl module (Random_Entry.pm) that is designed for use with mod_perl under Apache, although it also works as a CGI program under any web server (that supports Perl CGI programs).