X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=signature_stuff%2Fpick_a_quote.pl;h=cb1a432d054e3c36f8d8f1cb7d0c8db9906fdd1d;hb=551b16ff412a0204e2a86aa60aea2e91e7c3b9a4;hp=a2de7091fbd97283b582a21154ff6a34b48a18b7;hpb=efffd2d370164ed6b1db028b0d0071a6cbf7179d;p=lib.git diff --git a/signature_stuff/pick_a_quote.pl b/signature_stuff/pick_a_quote.pl index a2de709..cb1a432 100755 --- a/signature_stuff/pick_a_quote.pl +++ b/signature_stuff/pick_a_quote.pl @@ -11,33 +11,34 @@ my ($temp_file,$quote_file) = @ARGV; $temp_file ||= User->Home."/lib/signature_stuff/sigtemplate.txt"; $quote_file ||= User->Home."/lib/signature_stuff/quote.txt"; -my $sigfile = new IO::File User->Home."/.signature", 'w' or die "Unable to open ~/.signature for writing; $!"; +# 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 $!"; -my $quotesfile = new IO::File $quote_file,'r' or die "Unable to open $quote_file $!"; -my $template = ''; - -while (<$templatefile>) { - $template.=$_; -} +local $/; +my $template =<$templatefile>; undef $templatefile; -my $quotes = ''; - -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;