On Thu, Jul 12, 2001 at 11:35:59AM -0400, darren chamberlain wrote:
> Chris Fuchs <[EMAIL PROTECTED]> said something to this effect on 07/11/2001:
> > #!/usr/local/bin/perl
> > #randsig.pl, by Don Blaheta. Released into public domain, blah, blah, blah.
> > # Generates a signature randomly from a single file of witty quotes which
> > # the user maintains; the quotes can be multi-line, and are separated by
> > # blank lines.
>
> This is too much work. Try this:
>
> #!/usr/bin/perl
>
> my $fortunes = "$ENV{HOME}/.randsig";
> my $fortfile = "$ENV{HOME}/.sig"
> my $fortune;
>
> my @f = do {
> local *F;
> local $/ = "\n\n";
> open F, $fortunes or die $!;
> <F>;
> }
>
> chomp($fortune = $f[rand @f])
>
> {
> local *F;
> open F, ">$fortfile" or die $!;
> print F $fortune;
> }
>
> # END
Yes I've been meaning to rewrite it but in the context of
the original posted script, this is what I meant:
#!/usr/local/bin/perl
my $fortfile = $ARGV[0];
my $fortunes = $ARGV[1];
my $fortune;
my @f = do {
local *F;
local $/ = "\n\n";
open F, $fortunes or die $!;
<F>;
};
chomp($fortune = $f[rand @f]);
my $g = do {
local *G;
undef $/;
open G, $fortfile or die $!;
<G>;
};
$g=~s/%QUOTE%/$fortune/;
print $g;
# END
This of course assumes that there is no whitespace between
each quote. I've not figured out how to change $/ to deal
with spaces between quotes - any help is greatly appreciated.
Since we are on the subject and not having given much thought
... (and yes this probably should be another post) ... I've
often come across neat quotes which I'd like to extract, should
I be using a filter to do this and if so has anyone come out
with anything robust enough to handle most the situations that
I'd be likely to see?
--
If I have seen further it is by standing on the shoulders of giants.
-Isaac Newton