Perl Sigmaker

Just an update to my signature maker in Perl. I’ve added code to sub in my geek code block:

#!/usr/bin/perl
use warnings;
use strict;
use File::Copy;

# sigmaker - makes signature blocks using a templace and the fortune program
my $USER            = "imbrius"; #getlogin();
my $HOME            = $ENV{'HOME'};
my $FORTUNE         = "/usr/games/fortune";
my $GEEKCODE_FILE   = "$HOME/geekcode";
my $TEMPLATE        = "$HOME/.signature_template";
my $FORTUNE_STRING  = "_fortune_";
my $GEEKCODE_STRING = "_geekcode_";

open (FTEMPLATE, $TEMPLATE)      or die $!;
open (SIG, ">$HOME/.signature")  or die $!;
open (GEEKCODE, $GEEKCODE_FILE)  or die $!;

my $fortune_text  = `$FORTUNE`;
local $/          = undef;
my $geekcode_text = <GEEKCODE>;
$/                = "\n";
my $line;

while ($line = <FTEMPLATE>) {
        $line =~ s/$FORTUNE_STRING/$fortune_text/;
        $line =~ s/$GEEKCODE_STRING/$geekcode_text/;
        print SIG $line;
}

close SIG;
close FTEMPLATE;
close GEEKCODE;
copy("$HOME/\.signature", "/home/homelan/tmp/sig_$USER\.txt") or die $!;
chmod (0644, "/home/homelan/tmp/sig_$USER\.txt") or die $!;
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: