inperlquest has asked for the wisdom of the Perl Monks concerning the following question:
I am to process File2 using File1 in iterative comparison, but I get the second line from File2 repeated 3 times in the XML result, unlike what I expect
Output as I want it:
<tag1>1234</tag1>
<tag1_1>ABC</tag1_1>
<tag1_2>10</tag1_2>
</tag1>
<tag1>2345</tag1>
<tag1_1>PQR</tag1_1>
<tag1_2>34</tag1_2>
<tag1_1>XYZ</tag1_1>
<tag1_2>37</tag1_2>
<tag1_1>LMN</tag1_1>
<tag1_2>14</tag1_2>
</tag1>
I see only the line with PQR from File2 repeating all 3 times in the output now
This is my code:while (($line1 = <FILE1>) & ($line2 = <FILE2>)) { @inv1 = split (',',$line1); chomp (@inv1); @inv2 = split (',',$line2); chomp (@inv2); if ($inv1[1] == $inv2[0]) { for ($i = 1; $i <= $inv1[0]; $i++) { ## xml printing from file2 $line2; } } } ##while
What am I doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loop through two files in comparison
by GrandFather (Saint) on Aug 13, 2012 at 04:02 UTC | |
by inperlquest (Initiate) on Aug 13, 2012 at 05:49 UTC | |
by GrandFather (Saint) on Aug 13, 2012 at 06:29 UTC | |
by Mr. Muskrat (Canon) on Aug 13, 2012 at 20:44 UTC | |
by inperlquest (Initiate) on Aug 14, 2012 at 03:10 UTC | |
by Mr. Muskrat (Canon) on Aug 14, 2012 at 04:42 UTC |