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);

In reply to Re: Searching a collection of signatures by mr_mischief
in thread Searching a collection of signatures by FoxtrotUniform

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.