#!/usr/bin/perl #randsig.pl, by Don Blaheta. Released into public domain, blah, blah, blah. # Generates a signature randomly from a single file of witty quotes which # the user maintains; the quotes can be multi-line, and are separated by # blank lines. # Modifications by Glenn Maynard: # Put your own signature in a file (typically ~/.sig), and your quotes in # another file (ie ~/.randsig). Put "%QUOTE%" in your signature file where # you want a quote replaced. (It will always be the same quote ... if you're # crazy enough to want more then one quote in your signature do it yourself :) # To simply output your sig with no quote (%QUOTE removed), don't specify # a quotefile. $home = $ENV{"HOME"}; if ($#ARGV lt 0 or $#ARGV gt 1) { print "Usage: $^X sigfile [quotefile]\n"; exit 1; } # determine the quote if ($#ARGV eq 1) { open (FI, "$ARGV[1]") or die "Can't open $ARGV[1]"; # count the quotes $sig[0] = 0; while () { $sig[$#sig + 1] = tell if /^$/; } # read one srand; seek(FI, $sig[int rand ($#sig + .9999)], SEEK_SET) or die "Can't seek"; while () { last if /^$/; $msg .= $_; } } open (SIG, "$ARGV[0]") or die "Can't open $ARGV[0]"; while () { $_ =~ s/%QUOTE%/$msg/; print "$_"; } #Uncomment the next three lines if you also want your sig to be #outputted to ~/.sig (I do this because of some vi macros I have). # removed: read tee(1)