Monks, I'm struggling to find a solution to this seemingly simple problem. Please guide me towards salvation.
There are two csv files of which I'm to convert File2 into nested XML. Handcoding the logic, as the library doesn't have the required modules.
File 1
-------
1,1234
3,2345
File 2
---------
1234,ABC,10
2345,PQR,34
2345,XYZ,37
2345,LMN,14
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?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.