spydermonkey
Programmer
I've been working on this for three days and I'm getting so lost and frustrated and was wodnering if anyone could offer solutions or advice on how this could be accomplished.
There is a text file that looks like this
I need to reorder each ==== separated content to look like:
So while passing through the FIRST sample from above, it would be rewritten as
The phone numbers go first, if a 2nd number doesn't exist it'll be produce ,, so it's no problem. It matches only the first 2 numbers and the first $price, the rest is "other data".<p>
The snippet below works on the money but the problem is, I lose ALL the text other than the money for that time. I need all the text saved in a variable so I can re-order everything.
Any help would be much appreciated!
MY CODE
There is a text file that looks like this
Code:
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 down 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
I need to reorder each ==== separated content to look like:
Code:
phone1, phone2 (if it exists), $price, everything else
So while passing through the FIRST sample from above, it would be rewritten as
Code:
330-702-8787,702-8787,$154,900,Other Mahoning County
Columbiana, Lake Arrowhead Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from . A must see!
The phone numbers go first, if a 2nd number doesn't exist it'll be produce ,, so it's no problem. It matches only the first 2 numbers and the first $price, the rest is "other data".<p>
The snippet below works on the money but the problem is, I lose ALL the text other than the money for that time. I need all the text saved in a variable so I can re-order everything.
Any help would be much appreciated!
MY CODE
Code:
#!/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;
my $price = $_;
for ( 0 .. 1)
{
$price =~ m/
(
\$
(?:\d{1,3},?)+
(?:\.\d{0,2})?
(?![.\d])
)
/x;
$price = "$1";
}
print "$price\n";
}
close (WRITETO) or die "Cannot close $writeto: $!";
close (READFROM) or die "Cannot close $readfrom: $!";