X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=signature_stuff%2Fpick_a_quote.pl;h=83f319ad6cef1a9ab0b4b6f0cb83450c23384a37;hb=c14dbc4434aa3df066be8c6e0326236e6bff6384;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..83f319a 100755 --- a/signature_stuff/pick_a_quote.pl +++ b/signature_stuff/pick_a_quote.pl @@ -13,28 +13,31 @@ $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 $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/;