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


    In reply to Re: Rhyme generator by Brovnik
    in thread Rhyme generator by mpolo

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  4. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  5. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  6. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  7. Please read these before you post! —
  8. Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  9. You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  10. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  11. See Writeup Formatting Tips and other pages linked from there for more info.