in reply to Re: Combining client phone lists
in thread Combining client phone lists

Thanks for the tip about "normalizing whitespace." The input is supposed to be three different input files (to simulate three salesmen's phone lists) and not all part of one file.

I probably didn't explain that well enough. When I run the code, I'm not getting Bob Wilson but once. I don't know why he'd show up twice in yours...perl sure is a tricky lang.

Here's the output I'm getting:

Bob Cartwright 8219870089 Bob Wilson 3324549932, 8888212248 Felix Harris 4333448711 Freddie Sonere 4429089 Gloria Simpson 8215449341 Sam Burr 4550327 Wanda Smith 4449721, 3324329887


How do I spy on the input to recognize when a client name has been read with more than one phone number and output a list of those?

For example, if I have Gloria Simpson showing up in one list w/ her home number and in another list with her cell number, how do I make a list of her (and others w/ multiple ph. numbers) like this:

Gloria Simpson 888324543, 7338733 Someone Else 44409323, 4332111


'Preciate your help.

Replies are listed 'Best First'.
Re^3: Combining client phone lists
by GrandFather (Saint) on Apr 20, 2007 at 05:29 UTC

    Ok, three files, Bob Wilson white space fixed and it still works as I'd expect and, as far as I can tell, in the fashion you desire. Where's the problem?

    use strict; use warnings; open TEMP, '>', 'temp1.txt'; print TEMP <<FILE; Wanda Smith (332)432-9887 Freddie Sonere 442-9089 Bob Wilson 332-454-9932 FILE close TEMP; open TEMP, '>', 'temp2.txt'; print TEMP <<FILE; Bob Cartwright (821)987-0089 Felix Harris 433.344.8711 Bob Wilson (888)821- 2248 FILE close TEMP; open TEMP, '>', 'temp3.txt'; print TEMP <<FILE; Sam Burr 455-0327 Gloria Simpson (821)544-9341 Wanda Smith 444-9721 FILE close TEMP; my %bigList; local @ARGV = qw(temp1.txt temp2.txt temp3.txt); while (<>) { chomp $_; next unless length; my $inp = $_; my $client = $inp; my $num = $inp; $client =~ tr/0-9().-//d; $client =~ s/\s*$//; $num =~ tr/ a-zA-Z().-//d; #make big list $bigList{$client}{$num}++; } for my $one (sort keys %bigList) { print "$one ", join ', ', sort {$a <=> $b} keys %{$bigList{$one}}; print "\n"; }

    Prints:

    Bob Cartwright 8219870089 Bob Wilson 3324549932, 8888212248 Felix Harris 4333448711 Freddie Sonere 4429089 Gloria Simpson 8215449341 Sam Burr 4550327 Wanda Smith 4449721, 3324329887

    DWIM is Perl's answer to Gödel
      I'm trying to make a list of those clients who have more than one phone number, so that the output would be something like this:

      Bob Cartwright 8219870089 Bob Wilson 3324549932, 8888212248 Felix Harris 4333448711 Freddie Sonere 4429089 Gloria Simpson 8215449341 Sam Burr 4550327 Wanda Smith 4449721, 3324329887 Clients with multiple phone numbers: Bob Wilson 3324549932, 8888212248 Wanda Smith 4449721, 3324329887

        So you want reporting code like:

        my @single = grep {keys (%{$bigList{$_}}) == 1} keys %bigList; my @multi = grep {keys (%{$bigList{$_}}) > 1} keys %bigList; for my $one (@single) { print "$one ", join ', ', sort {$a <=> $b} keys %{$bigList{$one}}; print "\n"; } print "\n\nClients with multiple phone numbers:\n\n"; for my $one (@multi) { print "$one ", join ', ', sort {$a <=> $b} keys %{$bigList{$one}}; print "\n"; }

        Prints:

        Gloria Simpson 8215449341 Sam Burr 4550327 Freddie Sonere 4429089 Felix Harris 4333448711 Bob Cartwright 8219870089 Clients with multiple phone numbers: Bob Wilson 3324549932, 8888212248 Wanda Smith 4449721, 3324329887

        DWIM is Perl's answer to Gödel
        Eh? I think I'm lost. Is your last reply a testimonial or a further question? As far as I can see, GrandFather already answered your problem exactly as you want.

        Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!