This is a fairly complex task for a "total noob." You need to know how to:

All those topics would be scattered through several chapters of any book on learning Perl, so don't feel bad if you struggle with it for a while. Start at the top of the list and work your way down: learn how to read and write files, how to loop through a file line-by-line, and so on, and you'll get there.

Just for fun, here's a one-liner solution that leverages the Unix sort utility so I don't have to do it in Perl. When you can figure out what this is doing, you won't be a noob anymore.

$ cat 1124577.txt Black, Joe 0987 Smith, Sue 0534 Brown, Andy 587-0986 Galt, John (212)-555-1212 $ perl -ne 'print if s|^(.*\S)\s+(\(\d\d\d\)-)?(\d\d\d-)?(\d\d\d\d)|$1 + . " " . ($2?$2:"(333)-") . ($3?$3:"321-") . $4|e' 1124577.txt | sort Black, Joe (333)-321-0987 Brown, Andy (333)-587-0986 Galt, John (212)-555-1212 Smith, Sue (333)-321-0534

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.


In reply to Re: trying to format a phone list by aaron_baugher
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.