And my comments are this: run this code and ask questions :)

use strict; use warnings; my( $area_code, $extension ) = ( 333, 321 ); while (<DATA>) { my ($number) = $_ =~ /\s([0-9()-]+)/; $number =~ s/\D//g; if (length( $number ) == 4) { $number = $area_code . $extension . $number; } elsif (length( $number ) == 7) { $number = $area_code . $number; } elsif (length( $number ) == 10) { # do nothing } else { warn "could not parse $number\n"; next; } $number =~ s/(\d{3})(\d{3})(\d{4})/($1)-$2-$3/; $_ =~ s/([0-9()-]+)/$number/; print; } __DATA__ Black, Joe 0987 Smith, Sue 0534 Brown, Andy 587-0986 Smith, Pam (615)-895-1010
What this code essentially does is pull out things that look like phone numbers from each line. Then removes non-digits and checks the length of what is left. Based on that length, you can determine whether you need to add your default area code (333) and/or the default extension (321). Then you format the final number and substitute that back into your original line.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: total noob trying to format a phone list by jeffa
in thread trying to format a list by sonikd

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.