<?xml version="1.0" encoding="windows-1252"?>
<node id="890866" title="Re^7: incrementing already existing file" created="2011-03-01 18:35:55" updated="2011-03-01 18:35:55">
<type id="11">
note</type>
<author id="698926">
broomduster</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;
With your program Newfile is replaced by B set of values. How do I make it to take A set first and go to B set.
&lt;/i&gt;&lt;/blockquote&gt;
So what you have is two collections of numbers in the file you open as MYFILE.  One set is labeled 'A' in column 3 and the other is labeled 'B' in column 3.  The values in column 5 are an index, and the values in the last column are the ones you need to collect and add to NEWF.
&lt;p&gt;
What I said before is still mostly what you need to do.  Here's a revised outline of the code you need to write:
&lt;ul&gt;
&lt;li&gt;
Declare two arrays, one to hold the values from lines where column 3 is 'A' and another for lines where column 3 is 'B'.  Something like:
&lt;c&gt;
my( @a_vals, @b_vals );
&lt;/c&gt;
&lt;/li&gt;
&lt;li&gt;
Read each line from MYFILE, use [doc://split] to take it apart:
&lt;c&gt;
my( $type, $index, $value ) = ( split /\s+/ )[2, 4, -1];
&lt;/c&gt;
&lt;/li&gt;
&lt;li&gt;
Now you just put &lt;c&gt;$value&lt;/c&gt; into the appropriate array by checking what &lt;c&gt;$type&lt;/c&gt; is.  An easy way to do that is with &lt;c&gt;if/else&lt;/c&gt;, but I'm going to let you figure out the details.  If you have Perl 5.10 or later, a nice way to handle this is with [http://perldoc.perl.org/perlsyn.html#Switch-statements|given/when].
&lt;/li&gt;
&lt;li&gt;
Now change the &lt;c&gt;while ( &lt;NEWF&gt; )&lt;/c&gt; loop to insert the collected values where you want them.  You get to figure out that part, as well.
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
You didn't show a sample of what the output should look like, so this is as far as I can go with what you've posted.  If the output should have both 'A' and 'B' values at the end of a line, you do one thing.  If you need two lines (one for each of the 'A' and 'B' values), you do something different.  But we can't know unless you tell us.  Which leads me to the following advice about how to get along well on PerlMonks:
&lt;ul&gt;
&lt;li&gt;
Show your code. You did that. ++
&lt;/li&gt;
&lt;li&gt;
Show sample data. You did that, but we had to ask more than once.  And this last time, you posted &lt;i&gt;way&lt;/i&gt; more data than necessary to show a typical sample.  About five lines of each of the 'A' and 'B' types would have been enough.
&lt;/li&gt;
&lt;li&gt;
Show the output you're getting &lt;i&gt;and&lt;/i&gt; the output you want.  You did that after we asked the first time, but when you came back with more questions and I asked for sample input &lt;b&gt;and&lt;/b&gt; sample output, you posted input but no sample output.
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I think you have enough additional information now to "fix" my code to do what you want.  Give it a shot and come back with questions if you run into trouble.</field>
<field name="root_node">
890461</field>
<field name="parent_node">
890824</field>
</data>
</node>
