Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine Text Lists

Status
Not open for further replies.

V00D00

Technical User
Jul 11, 2005
78
US
I have two text files that contain customer information. One is from a specialty lead source, the second is from a generic lead source.

I looking to take these two lists in to a file so that they are ordered in an alternating pattern based on the total number of records for each file.

For example. List A has 5 records. List B has 10 records. I would like to have the new list ordered equally between the records from A and B.

New File Would be Structured Like This.

A - Record From List A
B - Record From List B
B - Record From List B
A - Record From List A
B - Record From List B
B - Record From List B
A - Record From List A
B - Record From List B
B - Record From List B
A - Record From List A
B - Record From List B
B - Record From List B
A - Record From List A
B - Record From List B
B - Record From List B

Any help is always appreciated.
 
You can't really order them unless there's a given assumption that they both match the same distribution, which almost NEVER happens

Code:
Read FileA into @arrayA
Read FileB into @arrayB
$counta=$#arrayA;
$countb=$#arrayB;
$ratio=$counta/$countb;
foreach(@arrayB) {
  print $_;
  $counter_b++;
  if ($counter_b%$ratio == 0) {
    print $arrayA[$counter_a];
    $counter_a++;
  }
}

NOT Tested, but should give you a starting point

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I thought about posting an array based solution, but decided against it as I'd get into trouble with Trojan [smile]
 
I thought about assigning a value to each file that would be used to help disperse the items evenly through the new file. One of the problems I am running in to is that its not just going to be 2 files. It may be 2 files, but it may be up to 10. This way using the values assigned I can track them uniquely in the file and sort accordingly. Now I am looking for a module that will evenly distribute like this.

VD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top