spydermonkey
Programmer
This will be a lengthy post and I appologize, the question is lengthy but the problem shouldn't be.
I have a config txt file where I have something like:
I am building an array to read each new line as it's own value. Then I have a regex to separate the left side and the right side of || into their own array.
Reason for this is.. I have a real text file I need to perform s/// for. Every time the left side of || appears in the code it needs to be replaced with the right side.
I test printed both @first_half and @second_half and get EXACTLY what I needed. The problem is in the output file, it's hard to explain but it's not right. It should print out the file as it was originally with only the s/// changes.
This is the script itself
This is the source file
This is the reulsts:
Thanks for all your help!
I have a config txt file where I have something like:
Code:
bdroom || bedroom
clst || closet
this string || ---
bowl of || plate of
apple || pear
php || ---
love || hate
I am building an array to read each new line as it's own value. Then I have a regex to separate the left side and the right side of || into their own array.
Reason for this is.. I have a real text file I need to perform s/// for. Every time the left side of || appears in the code it needs to be replaced with the right side.
I test printed both @first_half and @second_half and get EXACTLY what I needed. The problem is in the output file, it's hard to explain but it's not right. It should print out the file as it was originally with only the s/// changes.
This is the script itself
Code:
$/="\n";
my @split_strings;
my @first_half;
my @second_half;
#########
# open our replace file
#########
open (READFROM, "$readfrom") or die "Cannot open $readfrom: $!";
#########
# Prepare our file into an array
#########
while ( <READFROM> )
{
chomp;
push(@split_strings,$_);
}
close (READFROM) or die "Error: $!";
########
# our separator to split the array in two
########
my $sep = qr/\Q||\E/;
#my $sep = "\Q||";
##########
# begin separating our data
##########
foreach my $line (@split_strings)
{
my ($first,$second) = $line =~ /^(.+)\s+$sep\s+(.+)$/;
push @first_half, $first;
push @second_half, $second;
}
#######
# remove our ---'s we had to setup
#######
foreach (@first_half) { print "$_\n"; }
print "\n";
foreach my $line (@second_half)
{
#$line =~ s/---/ /;
print "$line\n";
}
#######
# Open our source and output files
#######
open (SOURCE, "$sourcefile") or die "Cannot open $sourcefile: $!";
open (WRITETO, ">$writeto") or die "Cannot open $writeto: $!";
#######
# All replacements are done here
#######
while ( my $piece = <SOURCE> ) {
foreach ( 0 .. $#first_half ) {
$piece =~ s/$first_half[$_]/$second_half[$_]/;
print WRITETO "$piece\n";
}
}
#######
# close filehandles
#######
close (SOURCE) or die "Error occured for $sourcefile: $!";
close (WRITETO) or die "Error occured for $writeto: $!";
This is the source file
Code:
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
====
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 purchase. 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 friend 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
====
This is the reulsts:
Code:
You’ll love this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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!
You’ll love this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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!
You’ll love this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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!
You’ll love this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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!
You’ll love this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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!
You’ll love this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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!
You’ll hate this Beautiful Cape Cod on the Boardman side of Southern Blvd. 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
Other Mahoning County $154,900
Other Mahoning County $154,900
Other Mahoning County $154,900
Other Mahoning County $154,900
Other Mahoning County $154,900
Other Mahoning County $154,900
Columbiana, Lake Arrowhead
Columbiana, Lake Arrowhead
Columbiana, Lake Arrowhead
Columbiana, Lake Arrowhead
Columbiana, Lake Arrowhead
Columbiana, Lake Arrowhead
Columbiana, Lake Arrowhead
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
Unique, condo home w/sunroom, fireplace & more! $154,900. Lease from $995. A must see!
330- 702-8787
330- 702-8787
330- 702-8787
330- 702-8787
330- 702-8787
330- 702-8787
330- 702-8787
702-8787
702-8787
702-8787
702-8787
702-8787
702-8787
702-8787
====
====
====
====
====
====
====
Campbell $400
Campbell $400
Campbell $400
Campbell $400
Campbell $400
Campbell $400
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
***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
***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
***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
***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
***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
***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
cashflowforlife.com
cashflowforlife.com
cashflowforlife.com
cashflowforlife.com
cashflowforlife.com
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.
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.
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.
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.
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.
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.
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
CALL 24 HOURS/DAY
CALL 24 HOURS/DAY
CALL 24 HOURS/DAY
CALL 24 HOURS/DAY
CALL 24 HOURS/DAY
CALL 24 HOURS/DAY
Toll Free 1-888-534-9659 ID#3006
Toll Free 1-888-534-9659 ID#3006
Toll Free 1-888-534-9659 ID#3006
Toll Free 1-888-534-9659 ID#3006
Toll Free 1-888-534-9659 ID#3006
Toll Free 1-888-534-9659 ID#3006
Toll Free 1-888-534-9659 ID#3006
or visit our website at
or visit our website at
or visit our website at
or visit our website at
or visit our website at
or visit our website at
or visit our website at
zerodownhousesforsale.com
zerodownhousesforsale.com
zerodownhousesforsale.com
zerodownhousesforsale.com
zerodownhousesforsale.com
zerodownhousesforsale.com
zerodownhousesforsale.com
====
====
====
====
====
====
====
Boardman $157,000
Boardman $157,000
Boardman $157,000
Boardman $157,000
Boardman $157,000
Boardman $157,000
Boardman $157,000
COLONIAL/1 ACRE
COLONIAL/1 ACRE
COLONIAL/1 ACRE
COLONIAL/1 ACRE
COLONIAL/1 ACRE
COLONIAL/1 ACRE
COLONIAL/1 ACRE
WOW!
WOW!
WOW!
WOW!
WOW!
WOW!
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
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
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
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
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
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
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
David Realty 330-758-8363
David Realty 330-758-8363
David Realty 330-758-8363
David Realty 330-758-8363
David Realty 330-758-8363
David Realty 330-758-8363
330-758-8363
330-758-8363
330-758-8363
330-758-8363
330-758-8363
330-758-8363
330-758-8363
====
====
====
====
====
====
====
Boardman $475
Boardman $475
Boardman $475
Boardman $475
Boardman $475
Boardman $475
Boardman $475
A BARGAIN - 0 DOWN
A BARGAIN - 0 DOWN
A BARGAIN - 0 DOWN
A BARGAIN - 0 DOWN
A BARGAIN - 0 DOWN
A BARGAIN - 0 DOWN
A BARGAIN - 0 DOWN
$475 & up/mo.
$475 & up/mo.
$475 & up/mo.
$475 & up/mo.
$475 & up/mo.
$475 & up/mo.
$475 & up/mo.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
2 Bedroom, extra sharp ranch. Ready to occupy, not for rent. Easy to purchase. 2 homes available.
7372 Oregon Trail
7372 Oregon Trail
7372 Oregon Trail
7372 Oregon Trail
7372 Oregon Trail
7372 Oregon Trail
7372 Oregon Trail
7421 Siera Madre
7421 Siera Madre
7421 Siera Madre
7421 Siera Madre
7421 Siera Madre
7421 Siera Madre
7421 Siera Madre
All Credit Considered
All Credit Considered
All Credit Considered
All Credit Considered
All Credit Considered
All Credit Considered
All Credit Considered
Jim Rich Realty 330-783-9300
Jim Rich Realty 330-783-9300
Jim Rich Realty 330-783-9300
Jim Rich Realty 330-783-9300
Jim Rich Realty 330-783-9300
Jim Rich Realty 330-783-9300
Jim Rich Realty 330-783-9300
====
====
====
====
====
====
====
North Jackson
North Jackson
North Jackson
North Jackson
North Jackson
North Jackson
North Jackson
JACKSON MEADOWS
JACKSON MEADOWS
JACKSON MEADOWS
JACKSON MEADOWS
JACKSON MEADOWS
JACKSON MEADOWS
JACKSON MEADOWS
Custom built 3&4 bedroom homes
Custom built 3&4 bedroom homes
Custom built 3&4 bedroom homes
Custom built 3&4 bedroom homes
Custom built 3&4 bedroom homes
Custom built 3&4 bedroom homes
Custom built 3&4 bedroom homes
330-538-4663 or 330-503-1985
330-538-4663 or 330-503-1985
330-538-4663 or 330-503-1985
330-538-4663 or 330-503-1985
330-538-4663 or 330-503-1985
330-538-4663 or 330-503-1985
330-538-4663 or 330-503-1985
330-538-4663
330-538-4663
330-538-4663
330-538-4663
330-538-4663
330-538-4663
330-538-4663
====
====
====
====
====
====
====
Dogs
Dogs
Dogs
Dogs
Dogs
Dogs
Dogs
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
PLEASE HELP! Being relocated-looking for a good home for my best friend 2 yr old blonde Cocker Spaniel well trained Loves to play Frisbee & Squeezy ball 330-797-8724
====
====
====
====
====
====
====
Austintown
Austintown
Austintown
Austintown
Austintown
Austintown
Austintown
STANJIM HOMES
STANJIM HOMES
STANJIM HOMES
STANJIM HOMES
STANJIM HOMES
STANJIM HOMES
STANJIM HOMES
1850 Countryside Drive
1850 Countryside Drive
1850 Countryside Drive
1850 Countryside Drive
1850 Countryside Drive
1850 Countryside Drive
1850 Countryside Drive
Kingwood Real Estate 793-2010
Kingwood Real Estate 793-2010
Kingwood Real Estate 793-2010
Kingwood Real Estate 793-2010
Kingwood Real Estate 793-2010
Kingwood Real Estate 793-2010
Kingwood Real Estate 793-2010
793-2010
793-2010
793-2010
793-2010
793-2010
793-2010
793-2010
====
====
====
====
====
====
====
Boardman $339,900
Boardman $339,900
Boardman $339,900
Boardman $339,900
Boardman $339,900
Boardman $339,900
Boardman $339,900
JUST move in! this home has over 3000 sq-ft; $339,900.
JUST move in! this home has over 3000 sq-ft; $339,900.
JUST move in! this home has over 3000 sq-ft; $339,900.
JUST move in! this home has over 3000 sq-ft; $339,900.
JUST move in! this home has over 3000 sq-ft; $339,900.
JUST move in! this home has over 3000 sq-ft; $339,900.
JUST move in! this home has over 3000 sq-ft; $339,900.
Cocca Real Estate 330-758-9904
Cocca Real Estate 330-758-9904
Cocca Real Estate 330-758-9904
Cocca Real Estate 330-758-9904
Cocca Real Estate 330-758-9904
Cocca Real Estate 330-758-9904
Cocca Real Estate 330-758-9904
330-758-9904
330-758-9904
330-758-9904
330-758-9904
330-758-9904
330-758-9904
330-758-9904
====
====
====
====
====
====
====
Thanks for all your help!