Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Tagline Rotator

by cajun (Chaplain)
on Feb 09, 2001 at 11:34 UTC ( [id://57356]=sourcecode: print w/replies, xml ) Need Help??
Category: E-Mail Programs
Author/Contact Info Mike Lewis cajun
cajun {at} cajuninc.com
Description: Rotate those tired .signature taglines automatically. Put your taglines in the file $siginfile, one tagline per line. Setup a cron job to run the script every few minutes. Now you won't have to manually change your .signature line.

Output looks something like this:

--

Backup not found! A)bort, R)etry or P)anic?
10:25pm up 23:22, 6 users, load average: 1.04, 1.10, 1.14

#!/usr/bin/perl -w

use strict;

my $debug=0;
my $home='/home/users/somebody';
my $siginfile="$home/sig/sigfile";
my $tearline="  \n";
my $uptime=`uptime`;
my $outfile="$home/\.signature";

open(INFILE,"$siginfile") or die "Can't open $siginfile :$!";
open(OUTFILE,">$outfile") or die "Sorry, but I can't write to $outfile
+ :$!";

my %hash;

while(<INFILE>){
  # build a hash with $. as key and $_ as value
  $hash{$.}=$_;
}

my $rand=rand($.);

my @body;

push (@body, $tearline);
push (@body, qq(  $hash{sprintf("%.0f", ($rand))}));
push (@body, $uptime);

if ($debug){
  print @body;
} else {
  print OUTFILE @body;
}

close INFILE;
close OUTFILE;
Replies are listed 'Best First'.
Re: Tagline Rotator
by vroom (His Eminence) on Feb 09, 2001 at 11:47 UTC
    I wrote one of these and changed my pine configuration so instead of piping an outgoing message to sendmail it ran the script to output my .signature and then passed it off to sendmail. CowboyNeal says mutt allows you to have a pipe in your sigfile settings which allows you to run the script every time you start composing a new message.

    vroom | Tim Vroom | vroom@cs.hope.edu
      Interesting thought. Thanks Tim. I also had thoughts about making it a daemon.
Re: Tagline Rotator
by Daddio (Chaplain) on May 29, 2001 at 07:46 UTC

    cajun, I think this is a great script. It's simple and straightforward.

    I would like to point out a couple of things that I think would help.

    First, I might recommend putting the open(OUTFILE,...) and close OUTFILE into the same else section as the print OUTFILE @body. There's no sense opening and closing a file if you don't need to in debug mode (and it will erase whatever is there if you are in debug mode - no sense doing that, either).

    Second, and more importantly, the sprintf("%.0f", ($rand) code may return a 0. To counter that, I would recommend these two changes:

    One, change

    my $rand=$rand($.);

    to

    my $rand = 0; $rand = int rand($.) until $rand != 0;

    Two, change

    push (@body, qq(  $hash{sprintf("%.0f", ($rand))}));

    to

    push (@body, qq(  $hash{$rand}));

    Hope this makes sense (it's been a long day :)!

    D a d d i o

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://57356]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found