#!/usr/bin/perl -w
use HTML::Entities;

@says = ("SAYS", "OFFERS", "DECLARES", "IMPARTS", "PROCLAIMS", "RECKONS", "REMARKS", "VOICES");

$quotenum=0;
$bprinting=0;
while(<>) {
    $says = $says[int(($#says+1)*rand())];
    if ($bprinting) {
        $bq="";
        if(/(.*?)<\/p>/) {
            $bprinting = 0;
            $bq = decode_entities($1);
        } else {
            /(.*?)<br\s+\/>/;
            $bq = decode_entities($1);
        }
        $bq=~s/<([A-Za-z0-9\-_|#:\@'`!\^\[\]\.]+)>/$1 $says:/g;
        print "$bq.\n";
        if($bprinting==0) {
            print "\n";
        }
        next;
    }

    if ( /quote."><b>\#(\d+)<\/b>/ ) {
        $quotenum=$1;
    }
    if ( /class="qt">(.*?)<\/p>/) {
        $bq = decode_entities($1);
        $bq=~s/<([A-Za-z0-9\-_|#:\@'`!\^\[\]\.]+)>/$1 $says:/g;
        print "Quote number $quotenum:\n";
        print "$bq.\n\n";
    }

    if ( /class="qt">(.*?)<br\s+\/>/) {
        $bq = decode_entities($1);
        $bq=~s/<([A-Za-z0-9\-_|#:\@'`!\^\[\]\.]+)>/$1 $says:/g;
        print "Quote number $quotenum:\n";
        print "$bq.\n";
        $bprinting=1;
    }
}
