I've played around with perl when it was time for me to find a phone number for my company. I know there is plenty|some modules that do such thing, but it was fun and instructive for me to do it whith no module.
you can use it to discover the numbers needed if you want your phone # to be like
1 800 MEATHOME 
just type
 ./script.pl MEATHOME 
and it gives you the right number !
or discover the possible words of your existing number(s) with
 ./script.pl -d=456123 

or completely usefulless guess how to type SMS
 ./script.pl -s=hello_dolly 

readmore to get the code

I know there is some bugs, for instance, it doesn't handle Digits in "SMS message typer" (so please don't mix), because handling digit depend on cellular phone brand. BTW improvement are on the way ...
#!/usr/bin/perl -l use strict; my @telear = ( ["+"], [" "], [ "A", "B", "C" ], [ "D", "E", "F" ], [ "G", "H", "I" ], [ "J", "K", "L" ], [ "M", "N", "O" ], [ "P", "Q", "R", "S" ], [ "T", "U", "V" ], [ "W", "X", "Y", "Z" ] ); my %telealph = ( ( map { $_ => $_ } ( 0 .. 9 ) ), ( map { my $d = $_; map { $_ => $d } @{ $telear[$d] } } ( 0 .. $#telear ) ) ); # big improvement by simonm my @tab = (); sub telecode { my $tocode = uc($_[0]); my $telecode = ""; foreach my $byte ( split //, $tocode ) { $telecode .= $telealph{$byte}; } return $telecode; } sub teledecode { my $tocode = $_[0]; my @telecode = (); my $i = 0; foreach my $byte ( split //, $tocode ) { $telecode[$i] = $telear[$byte]; $i++; } @tab = (); return arrangecode( "", 0, @telecode ); } sub arrangecode { my ( $first, $i, @dat ) = @_; foreach my $j ( @{ $dat[$i] } ) { if ( $i < ( @dat - 1 ) ) { @tab = arrangecode( $first . $j, $i + 1, @dat ); } else { $tab[@tab] = $first . $j; } } return @tab; } sub smstype { my $first = uc($_[0]); # uc() improvement by b10m $first =~ s/_/ /g; my $sms = ""; foreach my $j ( split //, $first ) { my $tou = $telealph{$j}; my $k = scalar( @{ $telear[$tou] } ); for my $i ( 0 .. $k ) { $sms = $sms . "$tou"; if ( $j eq $telear[$tou][$i] ) { $sms = $sms . ", "; last; } } } return $sms; } foreach my $toto (@ARGV) { if ( $toto =~ /-d=(\d+)/ ) { foreach my $tata ( teledecode($1) ) { print $tata} } elsif ( $toto =~ /-s=([a-zA-Z_]+)/ ) { print smstype($1); # typo fixed by b10m (thanks) } else { print telecode($toto); } }
--
dominix

In reply to play with phone numbers & w perl :) by dominix

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.