There is a text file I need to re-organize so it can be placed into a database in a specific order. A sample of this file can be found below along with an attempt I made in getting things to fall into place.

the file

You’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 ====
I have to read through this file and resort all the information in: phone1, phone2, price, everything else order. An example would be
330-758-9904,330-758-9904,$339,900,Boardman JUST move in! this home ha +s over 3000 sq-ft;. Cocca Real Estate
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.

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: $!";

In reply to pricing and phone number regexes by coldfingertips

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.