oko1 has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Phone number to word conversion
by JavaFan (Canon) on Nov 12, 2010 at 00:02 UTC | |
by oko1 (Deacon) on Nov 12, 2010 at 02:21 UTC | |
by JavaFan (Canon) on Nov 12, 2010 at 07:34 UTC | |
|
Re: Phone number to word conversion
by Anonymous Monk on Nov 11, 2010 at 23:19 UTC | |
by oko1 (Deacon) on Nov 12, 2010 at 02:14 UTC | |
by jethro (Monsignor) on Nov 12, 2010 at 00:08 UTC | |
by JavaFan (Canon) on Nov 12, 2010 at 00:26 UTC | |
by mjscott2702 (Pilgrim) on Nov 12, 2010 at 09:22 UTC | |
by JavaFan (Canon) on Nov 12, 2010 at 00:39 UTC | |
|
Re: Phone number to word conversion
by aquarium (Curate) on Nov 12, 2010 at 02:43 UTC | |
by oko1 (Deacon) on Nov 12, 2010 at 03:04 UTC | |
by aquarium (Curate) on Nov 12, 2010 at 03:47 UTC | |
by aquarium (Curate) on Nov 12, 2010 at 03:57 UTC | |
by oko1 (Deacon) on Nov 13, 2010 at 02:35 UTC | |
| |
by oko1 (Deacon) on Nov 13, 2010 at 02:33 UTC | |
|
Re: Phone number to word conversion
by Limbic~Region (Chancellor) on Nov 12, 2010 at 21:43 UTC | |
by oko1 (Deacon) on Nov 13, 2010 at 02:58 UTC |