############################################################################ # Copyright 1999-2000 by AltBlue [IRL: Marius Feraru] # # All rights reserved # # # # Distribute freely, except: # # * don't remove my name from the source or documentation # # (don't take credit for my work) # # * mark your changes # # (don't get me blamed for your possible bugs) # # * don't alter or remove this notice. # # # # No warrantee of any kind, express or implied, is included with this sw. # # Use at your own risk, responsibility for damages (if any) to anyone # # resulting from the use of this software rests entirely with the user. # # # # Send bug reports, bug fixes, enhancements, requests, flames etc., and # # I'll try to keep a version up to date. # # # # I can be reached as follows: # # E-Mail: AltBlue # # Homepage: http://www.deathsdoor.com/altblue # # ICQ: 34435556 # # IRC: N0i-Net (eg: irc.opsynet.com) channel: #noi # ############################################################################ # # last revision: 2000.02.12 # ########################## DESCRIPTION ################################### # Quotes generator. #----------------- # Function based on the code of 'Zappa quotes' by Robbert Heederik # with the obvious purpose of a lightweight fortune teller #---- # heh, sorry Robbert, but i choose a different approach # this way the speed it should be higher for small files also # the memory involved may be higher #------------------------------------------- # Usage: # ($quote,$info) = "e_generator($filename # [,$quote_separator [,$info_separator]]); # * returns ofc the $quote and $info for the choosen quote # (or undef if some errors occured >=-Q ) # * only the first argument is strictly required # .. the default values for the other arguments: # $quote_separator: % # $info_separator: -- # (ofc all of this is about to be the single elements of a line) ############################################################################ sub quote_generator { my ($file,$qsep,$isep); # what if some separator is a simple empty line? =] # .. or if qsep == isep? :P~ # let's take care of it if($#_ < 0) { return undef; } elsif ($#_ == 0) { $file = $_[0]; $qsep = '%'; $isep = '--'; } elsif ($#_ == 1) { $file = $_[0]; $qsep = $_[1]; $isep = '--'; } else { $file = $_[0]; $qsep = $_[1]; $isep = $_[2]; return undef if($qsep eq $isep); } open(QUOTES,$file) || return undef; my @lines = ; close(QUOTES); srand(time() % $$); my $idx = rand($#lines + 1) + 1; while ($idx>0) { last if ($lines[$idx-1] =~ /^$qsep$/); $idx--; } my ($quote,$info); while ($idx <= $#lines+1) { last if ($lines[$idx] =~ /^$qsep$/); if ($lines[$idx] =~ /^$isep$/) { $idx++; while ($idx <= $#lines+1) { last if ($lines[$idx] =~ /^$qsep$/); $info .= $lines[$idx++]; } last; } $quote .= $lines[$idx++]; } return ($quote,$info); } 1;