Monday, May 29, 2006

Picking a random quote or signature from a file [perl]

Generates a Random Signature from a signature file


sub pick_quote {
my $path = "/usr/signature/";
my $sigfile = "$path/signature.txt"; # Signature FILE
open (SIGS, "< $sigfile" ) or die "can't open $sigfile";
local $/ = "%%\n";
local $_;
my $quip;
rand($.) < 1 && ($quip = $_) while <SIGS>;
close SIGS;
chomp $quip;
print $quip || "ENOSIG: This signature file is empty.\n";

Sample Signature File

Signatures are a waste of bandwidth.
Help stamp out signatures.
'Calm down -- it's only ones and zeros.'
According to my calculations the problem doesn't exist.
A day for firm decisions!!!!! Or is it?
A few hours grace before the madness begins again.
A gift of a flower will soon be made to you.
A long-forgotten loved one will appear soon.

Buy the negatives at any price.