#!/usr/bin/perl -w # # $Id: random-signature.pl,v 1.1 2003/12/26 19:10:12 dope Exp dope $ # # Copyright by Christian Schneider # # Filename : ~/bin/random-signature.pl # Purpose : Create a random signature. # Author : Christian Schneider # Latest release : # # Last modified: [ 2003-12-26 20:18:41 ] # # For slrn () add # | set editor_command "random-signature.pl; your_editor" # | set signature "/home/username/.signature" # # For Mutt () add # | set signature="random-signature.pl|" # # You can use a mapping into Vim () # | nmap z :r!random-signature.pl; cat ~/.signature use strict; # The file with the sig-collection my $Siglist="$ENV{HOME}/.sigquotes"; # A permanent bit at begin/end of sig # my $Sigperm='Christian 'strcat' Schneider '; # The outputfile for the complete signature my $Sigfile="$ENV{HOME}/.signature"; my $Nquotes=0; my $quote; my $quotetxt=""; # Find a number of quotes # The delimiter at several sigs must be a `%´ open SIGLIST, "<$Siglist" || die "can't open $Siglist for read: $!\n"; while (){ if (/^%\s*$/) { $Nquotes++; } } close SIGLIST; # Pick random number $quote=int(rand($Nquotes)); # Extract random quote thing $Nquotes=0; open SIGLIST, "<$Siglist" || die "can't open $Siglist for read: $!\n"; open SIGOUT, ">$Sigfile" || die "can't open $Sigfile for write: $!\n"; # Skip first bit while () { if ($Nquotes==$quote) { last if /^%\s*$/; $quotetxt .= $_; } $Nquotes++ if /^%\s*$/; } # Put sig to file select(SIGOUT); print "-- \n"; # See "my $Sigperm". # Add this line before or after "$quotetxt". # print "$Sigperm\n"; print "$quotetxt"; close SIGOUT; close SIGLIST;