Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Tagline Rotator

by cajun (Chaplain)
on Feb 09, 2001 at 11:34 UTC ( #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 (Pope) 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
Node Status?
node history
Node Type: sourcecode [id://57356]
help
Chatterbox?
[Corion]: Meh. I think I have now the parts down that I want from a simple Javascript frontend for single-page- applications with a aPerl backend. But it seems that all Javascript templating modules either don't support two-way binding (which would be nice) or ...
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)
[Corion]: Two-way data binding means that if you change something in a text box, the corresponding variable in your Javascript gets updated immediately as well, and if you then change the variable, the corresponding text box also gets updated

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2017-03-30 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (355 votes). Check out past polls.