Quoth Loren Schooley: > Yet another good one. Thanks for all the angles, guys! Another slightly fancier one is attached to this message; usage info in the comments. -- -=-Don [EMAIL PROTECTED]=-=-<http://www.cs.brown.edu/~dpb/>-=- "All snakes who wish to remain in Ireland will please raise their right hands." -- Saint Patrick
#!/usr/local/bin/perl # randsig # © 1999 by Don Blaheta, freely licensed under terms of GPL. # # Make a file called ".randsig" in your home directory, with the # various random signatures separated by blank lines. Lines starting # with # are ignored. Call this script to output a random one. # # Fancy use #1: Make a macro in your editor program to call the script # and put the output in the current file's signature. In vi, # :map = /^-- $ jdG:r!randsig '' # should work (assuming there's already a signature present). # # Fancy use #2: Keep multiple signature files. For each special-purpose # sig file, put it in a file called .randsig.NAME in your home # directory, where NAME is something you pick; then call "randsig NAME" # and only quotes from that file will be selected. With no arguments, # randsig will search all such files. # Edit this line! Try to keep it to 76 characters or less. $sigline = '-=-Your [EMAIL PROTECTED]=-=-<http://www.bar.baz.edu/~foo/>-=-'; $home = $ENV{"HOME"}; $sigfile = "$home/.randsig"; if (@ARGV) { #use an alternate randsig file $filepref = shift @ARGV; $filepref = "$sigfile.$filepref"; } else { $filepref = "$sigfile"; } @files = glob("$filepref*"); srand; $tot = 0; foreach $file (@files) { open(FI, $file) or next; @sig = undef; while (<FI>) { $sig[$#sig + 1] = tell if /^$/; } $randnum = int rand($tot + $#sig); next if $randnum < $tot; $randnum -= $tot; seek(FI, $sig[$randnum], SEEK_SET) or die "Can't seek, aborting script"; undef $msg; while(<FI>) { next if /^\#/; last if /^$/; $msg .= $_; } $tot += $#sig; } # prints the random sig to the screen print STDOUT "$sigline\n$msg"; # Uncomment to make it write to your ~/.plan file; note that if you do # this, changes made directly to the ~/.plan will not persist! #open (PLAN,">$home/.plan"); #print (PLAN "See my office and home phone above. For further "); #print (PLAN "info on how to\nget in touch, try my Web page.\n"); #print PLAN "\n$sigline\n$msg"; #close PLAN; # Uncomment to save the signature to a ~/.sig file #open (SIG,">$home/.sig"); #print SIG "-- \n$sigline\n$msg"; #close SIG;