\begin{Jobst Schmalenbach}
> #!/usr/bin/perl
> if($#ARGV lt 0 or $#ARGV gt 2) {
> print "Usage: $^X sigfile [quotefile]\n";
> exit 1;
> }
> # determine the quote
> if ($#ARGV eq 1) {
> open (FI, "$ARGV[1]") or die "Can't open $ARGV[1]";
> # count the quotes
> $sig[0] = 0;
> while(<FI>)
> {
> $sig[$#sig + 1] = tell if /^$/;
> }
> # read one
> srand;
> seek(FI, $sig[int rand ($#sig + .9999)], SEEK_SET) or die "Can't seek";
> # seek(FI, $sig[0], SEEK_SET) or die "Can't seek";
> $msg = <FI>;
> while (<FI>) {
> last if /^$/;
> $msg .= $_;
> }
> }
> open (SIG, "$ARGV[0]") or die "Can't open $ARGV[0]";
> while (<SIG>) {
> $_ =~ s/%QUOTE%/$msg/;
> print "$_";
> }
ouch. you must right C code, right? ;)
in the interests of code conservation:
#! /usr/bin/perl
open(TEMPLATE, shift) or die "Can't open template: $!\n";
{ local $/ = undef; @sigs = split(/\n\n/s, <>); }
while(<TEMPLATE>) {
s/%QUOTE%/$sigs[rand(@sigs)]/e;
print;
}
if you take the template from stdin (which is probably a good idea),
then you can get rid of the open() line too.
--
- Gus
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug