in reply to Rhyme generator

I just had some fun playing with this.

A couple of comments :

  1. The code to read in the dictionary is a bit inefficient. The folloing in Dictionary.pm speeds things up by removing surplus split/join code :
    our %dict; our %reversedict; sub read_dict { while (<DATA>) { chomp; if (/^([^\s]+)\s\s(.*)$/) { my ($key,$value) = ($1,$2); $dict{$key} = $value; $reversedict{$value} = $key; } } return; }
    This speeds up the initial read from 10+ seconds to 6.5 seconds on my machine.
  2. I also played with using Storable to speed up subsequent accesses.
    my $dict = "/tmp/Lingua::EN::Rhyme::Dictionary::DICT"; my $reversedict = "/tmp/Lingua::EN::Rhyme::Dictionary::REVDICT"; my $loaded = retrieve_dict(); sub store_dict { read_dict(); store(\%dict,$dict); store(\%reversedict,$reversedict); } sub retrieve_dict { my $ref = retrieve("DICT"); if ($ref) { %dict = %$ref; $ref = retrieve("REVDICT"); %reversedict = %$ref; } else { # Read in normal way and store read_dict(); store_dict(); } return 1; }
    This uses Storable to store and retrieve the dictionaries. It saves some time, but not a lot and leves the extra files around.

    I also started playing with storing this in a mysql DB, but haven't got that clean yet (it really needs a rewrite of all of Rhyme.pl.

  3. Hope that is of help.
    --
    Brovnik