Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am getting so frustrated. This is a repost of two previous posts. I've tried every example given and to no success. They all include numbers that aren't phone numbers and miss most of the numbers that are. I tried doing ALL of them, even mix-matched with tr/0-9//cd; which I think is a bad idea because what this does (from what I THINK it does) is puts all numbers in a huge line and makes a number out of them. I can't do this because there are more numbers on a line than inside my phone number.
Here is some sample data (I have different log files, but here are two so you can see):
FILE1 Residential MLS #: 2094044 Status: Active-NORMLS LP: $125,204 SP: $ 9962 BEVERLY LANE STREETSBORO OH 44241- Unit/Lot #: Area: 1909 + Unit Floor #: Map Coordinate: P13A2 Subdivision/Complex: VANTAGE POINT Photos: Media: 6 Acres: 1/2 Yr. Tax : 732 County: Portage Owner/Agent: No Parcel ID# (PIN): TBA Year Built: 2003 Lot Dimensions: 18X52 School District: 6709/Streetsboro City List Type: ERS Irregular: N High School: MLS Cross Ref #: Sub Property Type: One Family List Date: 6/20/2003 MT: 253 Directions: CORNER FROST RD & ST RT 43 # Rooms: 4 # Bedrooms: 2 Total Baths: 1.1 Finished SqFt: 1080 LO #/Name: 2380 / Realty One (440) 248-2700 Office Web Site: www.rea +ltyone.com LA #/Name: 417391 / Mark J. Abbott (440) 975-0537 LA Email: m.abbott +@realtyone.com LA 2 #/Name: / LA 2 Email: SAC: 0 BAC: 2.5 OAC: None LockBox Desc: Compensation Explain: Fixer Upper: N Remarks: WILLIAM THOMAS HOMES VANTAGE PT CLUSTER TOWNHOMES! TWO BEDROO +MS,ONE & HALF BATHS,FULL BASEMENT! FIREPLACE! KITCHEN & LAUNDRY APPLI +ANCES! WOOD RAILINGS! COMMON AREA MAINTENANCE! 56 HILLSIDE & PATIO UN +ITS, TAXES ESTIMATED, EXTRA WINDOWS! 90% EFFIC FURNACE! PRIVACY FENCE +! PATIO.FURNISHED MODEL 9941 BEVERLY Broker Remarks: COMMISSION PAID ON BASE OF $114,900. CALL LISTING AGEN +T FOR INFORMATION ON TITLE WORK. ---------------------------------------------------------------------- +---------- Residential MLS #: 2130518 Status: Active-NORMLS LP: $125,500 SP: $ 1244 Meadow Run Copley OH 44321- Unit/Lot #: 20 Area: 1820 Unit Floor #: Map Coordinate: S27B3 Subdivision/Complex: Meadows of Copley Photos: Media: 1 Acres: 1/2 Yr. Tax : 9999 County: Summit Owner/Agent: Parcel ID# (PIN): 0 Year Built: 2004 Lot Dimensions: School District: 7703/Copley-Fairlawn City List Type: ERS Irregular: + N High School: Copley MLS Cross Ref #: Sub Property Type: Condominium List Date: 2/17/2004 MT: 11 Directions: Ridgewood Road to Jacoby Rd. to Copley Rd. east to The Mea +dows # Rooms: 5 # Bedrooms: 2 Total Baths: 2.1 Finished SqFt: LO #/Name: 2817 / Smythe, Cramer Co. (330) 836-9300 Office Web Site: + www.smythecramer.com LA #/Name: 302709 / Sheila Eaton (330) 864-5741 LA Email: sheilaeato +n45@aol.com LA 2 #/Name: / LA 2 Email: SAC: 0 BAC: 2.5 OAC: None LockBox Desc: Compensation Explain: Fixer Upper: N Remarks: Beautiful new constructionin The Meadows of Copley*1st class +amenities*448 sq ft finished lower level family rm*Vaulted ceilings*F +ully applianced*Spacious master suite*Bright, open and airy*10x10 pat +io. Broker Remarks: ---------------------------------------------------------------------- +---------- FILE2 Donna I. Stoner, ABR GRI Bolton-Johnston Associates of Grosse Pointe Phone 1: (313)884-6400, Email: donnastoner@realtor.com Buyers, Relocation, Residential, Sellers, Waterfront Property Add to Scratch Pad Contact me now Go to my site DONNA L. GORMLEY Johnstone & Johnstone Office: (313) 884-0600, Mobile: (313) 590-9253, Email: johnstone@reale +stateone.com buyer's agent, Listing agent, residential properties Add to Scratch Pad Contact me now Go to my site
As you can see, on some lines I MAY have more than one set of numbers so I need it to be picky and only select things that are numbers. Someone suggested http but there is no documentation. It shows how to validate one variable, which I can't get to work much less how to trim an entire text file into numbers it'll validate.
This is frustrating me so much because I checked everything I could on Phone Numbers in the super search and nothing helped, they all died in one way or another. Can someone give me a different perspective or show how to use that module? My last attempt was:
#!/usr/bin/perl use strict; # change the below line to the file you are reading FROM (your junk fi +le) my $read_from = "test2.txt"; # Change the below line to where you want your neat phone numbers to b +e printed my $save_to = "saved.txt"; my %seen; open(FILE, '<', "$read_from") or die "Unable to open file.txt for read +ing, $!"; while (<FILE>) { #s /[\n|\r]//g; tr/0-9//cd; #print "Testing with $_, result is "; m/(1[-| ]?)?\(?(\d{3})\)?[-| ]?(\d{3})[-| ]?(\d{4})/; #m|(1-)?\(?(\d{3})\)?-?(\d{3})-(\d{4})|; my $areacode = $2; my $exchange = $3; my $line = $4; print "($areacode) $exchange-$line\n"; $seen{"$areacode-$exchange-$line"}++; } close(FILE); open(SAVED, '>', "$save_to") or die "Unable to open $!"; print SAVED "$_\n" for (sort keys %seen); close(SAVED);
Edited by Chady -- formatting and readmore tags.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: phone number parsing refuses to work
by Happy-the-monk (Canon) on Mar 13, 2004 at 23:11 UTC | |
Re: phone number parsing refuses to work
by BrowserUk (Patriarch) on Mar 14, 2004 at 00:32 UTC | |
Re: phone number parsing refuses to work
by etcshadow (Priest) on Mar 14, 2004 at 01:57 UTC | |
Re: phone number parsing refuses to work
by graff (Chancellor) on Mar 14, 2004 at 00:33 UTC | |
Re: phone number parsing refuses to work
by Anonymous Monk on Mar 13, 2004 at 23:19 UTC | |
by Happy-the-monk (Canon) on Mar 13, 2004 at 23:29 UTC | |
Re: phone number parsing refuses to work
by converter (Priest) on Mar 14, 2004 at 15:54 UTC | |
Re: phone number parsing refuses to work
by mojotoad (Monsignor) on Mar 23, 2004 at 00:35 UTC |