I've got a small project brewing and have been adding features over the last 1.5 weeks. The most-recent feature I've added is a dict.org lookup for each word in my taxonomy.

The code looks like this (and works great):

sub define_term { my $definition = shift; my $dict = Net::Dict->new('test.dict.org'); my $result = $dict->define("$definition")->[1][1]; if (!$result) { $result = $dict->define(substr($definition, 0, -1))->[ +1][1]; } if ($result) { print $cgi->h3("Definition of $definition"); print $cgi->hr({-size=>'1'}); print $cgi->pre("$result"); } }

This returns a definition that looks like the following:

bean n 1: any of various edible seeds of plants of the family Leguminosae [syn: {edible bean}] 2: any of various seeds or fruits suggestive of beans 3: any of various leguminous plants grown for their edible seeds and pods [syn: {bean plant}] 4: informal terms for a human head [syn: {attic}, {bonce}, {noodl +e}, {noggin}, {dome}] v : hit on the head, esp. with a pitched baseball

These words are automagically wrapped in the response that comes back from dict.org, and that presentation isn't exactly ideal for my needs. I tried the various ::Wrap and unwrap modules, and none seem to do the job that I need.

I tried using Text::Flow::Wrap, Text::Wrap, Text::Wrap::Smart, and some hand-rolled regexes... without much success. It seems these modules are all designed to WRAP text, not UNwrap text.

In the above case, I'm trying to get the result that looks like (PM will wrap this somewhat, but what I'm trying to do is keep each numbered item on its own line, unwrapping each \d\..*, essentially):

bean n 1: any of various edible seeds of plants of the family. Legumin +osae [syn: {edible bean}] 2: any of various seeds or fruits suggestive of beans 3: any of various leguminous plants grown for their edible seeds +and pods [syn: {bean plant}] 4: informal terms for a human head [syn: {attic}, {bonce}, {noodl +e}, {noggin}, {dome}] v : hit on the head, esp. with a pitched baseball

Can others suggest a better way of doing what I'm trying to do?


In reply to Unwrapping the Dictionary by hacker

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • 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
  • 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;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.