I have a random signature picker for my email and newsgroup postings. It uses '%' at the start of a line so it will work with regular fortune files. It defaults to a file ~/.taglines if no arguments are given on the command line, or it will allow you to give it a file to read from.
It also will allow a semicolon at the beginning of a line to act as a comment. I did that so I could keep file version data at the top of the file, and it'l let me extend it in the future to maybe include metainfo such as extended quote attributions, definitions or etymology for a word, or editorial quips which are only included when over four lines is considered proper or the extra detail is really wanted.
If we could make yours and mine both work with the extended info, it'd let people search for fortunes within a larger file attributed to a particular person and such.
Here's mine:
#!/usr/bin/perl -w
use strict;
my $homedir = $ENV{HOME};
my $file;
if ( $ARGV[0] ) {
$file = $ARGV[0];
} else {
$file = "$homedir/.taglines";
}
open(TL, "$file") ||
die "$file could not be read: $!\n";
my $tags = 0;
while(<TL>) {
$tags++ if /^%$/;
}
my $which_tag = int(rand($tags));
$tags = 0;
seek(TL, 0,0);
while(<TL>) {
if(/^%$/) {
$tags++;
if($tags > $which_tag) {
exit(0);
}
} elsif(/^;/) {
} elsif($which_tag == $tags) {
print("$_");
}
}
exit(0);