coldfingertips has asked for the wisdom of the Perl Monks concerning the following question:
the file
I have to read through this file and resort all the information in: phone1, phone2, price, everything else order. An example would beYou’ll love this Beautiful Cape Cod on the Boardman side of Southern B +lvd. We can do a Rent-to-Own for a short time if you can qualify quickly for this 2-bedroom home wtih all appliances, full +basement and garage, with payments as easy as rent. We have only one home at these terms, so call 330-207-0989 NOW - it won’t + last long! ==== Other Mahoning County $154,900 Columbiana, Lake Arrowhead Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $ +995. A must see! 330- 702-8787 702-8787 ==== Campbell $400 ***BUY With “0” Down or land Contract. $400/mo. completely remodeled 3 + Bedroom Home in good area near High School. 291 Sanderson Ave. 330-759-2420 or cashflowforlife.com ==== Learn how you can stop renting and buy your own home, even with $0 dow +n and bad credit. Pre-recorded message explains how to order your special FREE report. CALL 24 HOURS/DAY Toll Free 1-888-534-9659 ID#3006 or visit our website at zerodownhousesforsale.com ==== Boardman $157,000 COLONIAL/1 ACRE WOW! We finally found the 4 bedroom home you’ve been looking for. Call our +office today for details and directions for the best buy in Boardman. Appraised at $157,000. Asking ONLY $139,900 David Realty 330-758-8363 330-758-8363 ==== Boardman $475 A BARGAIN - 0 DOWN $475 & up/mo. 2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to p +urchase. 2 homes available. 7372 Oregon Trail 7421 Siera Madre All Credit Considered Jim Rich Realty 330-783-9300 ==== North Jackson JACKSON MEADOWS Custom built 3&4 bedroom homes 330-538-4663 or 330-503-1985 330-538-4663 ==== Dogs PLEASE HELP! Being relocated-looking for a good home for my best frien +d 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724 ==== Austintown STANJIM HOMES 1850 Countryside Drive Kingwood Real Estate 793-2010 793-2010 ==== Boardman $339,900 JUST move in! this home has over 3000 sq-ft; $339,900. Cocca Real Estate 330-758-9904 330-758-9904 ====
The problem lies in the regexes. They can have more than one phone number so the first one it finds has to be first, then the second would be the second field (or you would get a phone1,,price set.330-758-9904,330-758-9904,$339,900,Boardman JUST move in! this home ha +s over 3000 sq-ft;. Cocca Real Estate
This regex I used on another script doesn't seem to be fully functional and it doesn't match 1-800 numbers. m|[(]?(\d{3})[. )-][ ]?(\d{3}\d?)[. -](\d{4})|g . This regex is for the prices but it only matches numbers that have a comma in them OR just $0, it refuses to match any other number including $475 which is in the text file. m/(\$([0-9,?])+)\s/; Can someone possibly take a look at the regexes and give me a better solution or possibly give ideas of a better way of going about doing something like this? This is the code-to-date
#!/usr/bin/perl use warnings; use strict; ##################### # configuration section ##################### my $readfrom = "test.txt"; ## change the above to the file you're reading from my $writeto = "output.txt"; ## change the above to the file you're writing to ##################### # do not edit below this line ##################### $/="====\n\n"; open (READFROM, "$readfrom") or die "Cannot open $readfrom: $!"; open (WRITETO, ">$writeto") or die "Cannot open $writeto: $!"; while ( <READFROM> ) { chomp; ## doesn't work # my $phone; # if (m|[(]?(\d{3})[. )-][ ]?(\d{3}\d?)[. -](\d{4})|g) # { # $phone = "$1 $2 $3"; # } # print "$phone\n"; ## $_ =~ m/(\$([0-9,?])+)\s/; my $price = $1; print "$price\n"; } close (WRITETO) or die "Cannot close $writeto: $!"; close (READFROM) or die "Cannot close $readfrom: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: pricing and phone number regexes
by davido (Cardinal) on Jun 05, 2004 at 03:11 UTC | |
by coldfingertips (Pilgrim) on Jun 05, 2004 at 03:31 UTC | |
by davido (Cardinal) on Jun 05, 2004 at 04:02 UTC | |
by coldfingertips (Pilgrim) on Jun 05, 2004 at 04:41 UTC | |
by davido (Cardinal) on Jun 05, 2004 at 04:51 UTC | |
|
Re: pricing and phone number regexes
by karmacide (Acolyte) on Jun 05, 2004 at 02:52 UTC |