Hi all. I'm a perl noob and having difficulty with a simple program to combine the textual phone lists.
I'm trying to combine multiple lists into one master list. Since different lists will have parentheses around the area code, or use dashes, etc. and be formatted differently, I'm stripping the phone numbers of those extraneous symbols and just ending with the client names and phone numbers, e.g., Wanda Smith (332)432-9887 should become Wanda Smith 3324329887.
Duplicates should show the name followed by the phone numbers separated by a comma.
After that I want to have a list of those clients who were on more than one list, and show their phone numbers.
My code is doing most of what I want (using a hash of a hash), but I'm having trouble making a list of those clients who are on more than one list. I want to print out those clients' names and phone numbers (separated by a comma).
Here's the 3 test files I'm using (separated by blank lines):
Wanda Smith (332)432-9887<br>
Freddie Sonere 442-9089<br>
Bob Wilson 332-454-9932<br><br>
Bob Cartwright (821)987-0089<br>
Felix Harris 433.344.8711<br>
Bob Wilson (888)821- 2248<br><br>
Sam Burr 455-0327<br>
Gloria Simpson (821)544-9341<br>
Wanda Smith 444-9721<br><br>
and here's my code so far for making the master list:
#combine client lists into one list
#strip all extraneous symbols
#! usr/bin/perl -w
while (<>) {
chomp($inp = $_);
$client = $inp;
$client =~ tr/0-9().-//d;
$num = $inp;
$num =~ tr/a-zA-Z().-//d;
$num =~ tr/ //d;
#make big list<br>
$bigList{$client}{$num}++;
}
for $one (sort keys %bigList) {
+
print "$one ", join ', ', sort {$a <=> $b} keys %{$bigList {$one}};
+
print "\n";
}
Thank you very much to anyone who can help me. :)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.