in reply to Phone number to word conversion
use 5.010; use strict; use warnings; my @map = qw [0 1 abc def ghi jkl mno pqrs tuv xyz]; my $words = `cat /usr/share/dict/words`; while (<DATA>) { chomp; s/[^0-9]+//g; s/[01]+/ /g; foreach my $_ (split) { my @c; for (my $i = 0; $i < length; $i++) { for (my $j = 2; $i + $j <= length; $j++) { push @c, substr $_, $i, $j; } } my $pat = join '|', map {my $_ = $_; s/(.)/[$map[$1]]/g; $_} @ +c; say for $words =~ /^($pat)$/mg; } } __DATA__ 234-5678
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Phone number to word conversion
by oko1 (Deacon) on Nov 12, 2010 at 02:21 UTC | |
by JavaFan (Canon) on Nov 12, 2010 at 07:34 UTC |