Other online diaries:
Tue, 03 May 2005
Random Ani sig thing - 15:13
The perl code may be found here and the source data is this files of quotes. It is not particularly difficult to change the code to use a different data source and different thing to print. As for the code, it would be pretty easy to implement a random selection of a quote every time the program runs. My ideal implementation however uses each quote from the file once until it runs out then starts over again, the same quote can not appear twice in a row.
To do the easy only random implementation I would only need the read_quote_file, serialise_quotes and remove_random_quote functions (it could in fact be simplified far more than this too). So I added command line options (give it an alternate data source, and alternate cache file, an alternate static sig content file, a unique option and a help option). Run as is it uses the default filenames that I set in the code and sits out a random quote.
For my usage the unique option maintains a cache of quotes that diminishes every time the program is run with the -u option. I used Data::Dumper to store the cache, messy and hackish but really easy to do. Anyway pretty basic code, did not take long to implement, and sure it can be simplified a lot (lets hope it does not get out of hand (on the recursive mkdir case, Tony removed a few more characters from Jeremy's example, maybe he should blog about it)) but it works and passes the test case I created for it (small files, missing files, running a thousand times, using various options, etc) though I did not bother making it handle bad input data correctly, oh well no matter.
Getting back into geeky things lightly.