A regular expression with substitution is one way. Some extras included:
my $phone = '1234567890'; # convert alpha mnemonics $phone =~ tr/A-PR-Z/222333444555666777888999/; $phone =~ tr/a-pr-z/222333444555666777888999/; # get rid of any nondigits $phone =~ s/\D//g; # format $phone =~ s/^(\d{3})(\d{3})(\d{4})$/{$1) $2-$3/; $phone =~ s/^(\d{3})(\d{4})$/$1-$2/; # no AC print $phone, $/;
(Added) 'perldoc perlre' is the primary reference. It should be installed with your perl.
After Compline,
Zaxo
In reply to Re: formatted phone number from variable
by Zaxo
in thread formatted phone number from variable
by powerhouse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |