Greeting, oh Holy Brethren in Perl! I've just run into a challenge, and I'm looking for a bit of... let's call it context, since I don't even know whether I'm making a mountain out of a molehill or if I'm underestimating the scope of the thing.

Problem: I've often thought of writing a script that would take a phone number and show the words in it (at least 3 letters in length) - no particular reason, just for the sake of playing around with it. Today, I had a bit of time to spare and dove into it... only to be brought to a screeching halt. Seems the thing isn't quite as simple as it appears at first glance; there are a few rules that need to be followed, plus some visual perception-type stuff and "what makes sense" type of stuff, too.

1) 0s and 1s don't count - they have no letter values - but
they do define where the words start/end. (Optionally, you 
could have a policy of using them in a "leet-speak" manner 
and letting them serve as 'o's and 'i's respectively.)

2) Sure, you could just slam all the digits in a contiguous 
(meaning, no 0s or 1s) number together and convert them to 
/[abc][def][ghi][jkl][mno][pqrs][tuv]/ for '234-5678',
which you would then match against a dictionary - but then, 
how do you get 'film' out of that (valid match for 3456)? 
You can't do /[abc]?[def]?[ghi]?[jkl]?/, etc., because that 
would match, e.g. 'ail' (245) - which isn't a valid combo.

3) Building an iteratively-exhaustive set of regexes to 
cover all valid positional combinations - e.g. 234-5670 
would mean looking at the character combinations for

234567|23456|34567|2345|3456|4567|234|345|456|567

- seems like a really hacky, ugly approach (I mean, we're 
*programming*, right? Supposed to let the computer do this 
kind of work for us and all that?)

Given all of the above, I've been trying to figure out an approach that makes sense and has some readable structure to it... and I've been failing miserably. When I got to the point of actually considering how to build approach #3, I gave up and decided to ask the help of my fellow coders.

Thanks in advance for any help offered.


--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

In reply to Phone number to word conversion by oko1

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.