hello Perlmonks, i have a phone list in a text file, the names and phone numbers are a bit jumbled up, i am wanting a script to sort them like this:

Black, Joe (333)-321-0987

Smith, Sue (333)-321-0534

Brown, Andy (333)-587-0986

Currently, they look something like this:

Black, Joe 0987

Smith, Sue 0534

Brown, Andy 587-0986

the area code on all numbers in the txt file will need to be (333) for example, and the exchange prefix is assumed to be 321 unless otherwise specified, such as the one example that shows 587 as the exchange prefix.

The names and numbers need to list in ascending alpha order by last name, no quotation marks, even columns, inserts area code as (333) unless otherwise marked, dashes between area code and exchange prefix and between line number

i found another post on here which would allow me to properly format the phone numbers, but i have no idea how i would incorporate that in a script or write a new script that would allow me to format an entire txt file and output it to another text file with the names/numbers correctly formatted. Thanks in advance for any help.

heres the other code i found:

#!/perl/bin/perl use strict; use warnings; # The assumption is that the number will always be exactly ten digits my $s = "0123456789"; print $s, "\n"; $s =~ s/^(\d{3})(\d{3})(\d{4})$/($1)$2-$3/; print $s, "\n"; __OUTPUT__ 0123456789 (012)345-6789

In reply to 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.