X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=signature_stuff%2Fpick_a_quote.pl;h=cb1a432d054e3c36f8d8f1cb7d0c8db9906fdd1d;hb=5568b67a3f7f122b8fe0b0b923c8c003c6c0acba;hp=1f1ab09ff17248cf817bef3cf53dd81e3a14696c;hpb=10fff37659bbe10892765c6db10f948fbe7888a3;p=lib.git diff --git a/signature_stuff/pick_a_quote.pl b/signature_stuff/pick_a_quote.pl index 1f1ab09..cb1a432 100755 --- a/signature_stuff/pick_a_quote.pl +++ b/signature_stuff/pick_a_quote.pl @@ -5,33 +5,40 @@ use strict; use IO::File; -my $sigfile = new IO::File "> /home/don/.signature"; -my $templatefile = new IO::File "/home/don/signature_stuff/sigtemplate.txt"; -my $quotesfile = new IO::File "/home/don/signature_stuff/quote.txt"; +use User; -my $template = ''; +my ($temp_file,$quote_file) = @ARGV; +$temp_file ||= User->Home."/lib/signature_stuff/sigtemplate.txt"; +$quote_file ||= User->Home."/lib/signature_stuff/quote.txt"; -while (<$templatefile>) { - $template.=$_; -} +# my $sigfile = new IO::File User->Home."/.signature", 'w' or die "Unable to open ~/.signature for writing; $!"; +my $templatefile = new IO::File $temp_file, 'r' or die "Unable to open $temp_file $!"; -undef $templatefile; +local $/; +my $template =<$templatefile>; -my $quotes = ''; +undef $templatefile; -while (<$quotesfile>) { - $quotes.=$_; +my $quote; +my $fortune; +if (-e $quote_file.'.dat' and open($fortune,'-|','fortune',$quote_file)) { + local $/; + $quote = <$fortune>; + close($fortune); + $quote =~ s/\n$//; +} +else { + my $quotes = ''; + my $quotesfile = new IO::File $quote_file,'r' or die "Unable to open $quote_file $!"; + local $/; + $quotes = <$quotesfile>; + undef $quotesfile; + my @quotes = split /\n*\%\n*/s, $quotes; + undef $quotes; + my $quote = $quotes[rand(@quotes)]; } -undef $quotesfile; - -my @quotes = split /\n*\%\n*/s, $quotes; -undef $quotes; - -my $quote = $quotes[rand($#quotes+1)]; $template =~ s/\[\%\s*quote\s*\%\]/$quote/; -print {$sigfile} $template; - -undef $sigfile; +print $template;