<?xml version="1.0" encoding="windows-1252"?>
<node id="995735" title="Re: EMPTY OUTPUT FILE GENERATED" created="2012-09-26 05:57:20" updated="2012-09-26 05:57:20">
<type id="11">
note</type>
<author id="918402">
2teez</author>
<data>
<field name="doctext">
Hi,&lt;p&gt;
&lt;i&gt;Please help me out to find my flaws&lt;/i&gt;&lt;br&gt;&lt;br&gt;
Please consider the following:&lt;br&gt;
&lt;ul&gt;
&lt;li&gt; It's a lot better, to use [doc://warnings]; and [doc://strict]; at the top of ones script&lt;/li&gt;
&lt;li&gt; It's modern ( ha ha... ) and a lot safer to use [doc://open] 3 arugments&lt;/li&gt;
&lt;li&gt;Barewords as filehandles might not be too good, you can use lexical variable of your choice.&lt;/li&gt;
&lt;li&gt;Lastly, you will want to close, your filehandles, as soon as they are [doc://open]ed&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
Below is the reconstruct of your script.&lt;br&gt;Please, note I used regex to get what I &lt;i&gt;assumed&lt;/i&gt; to be first column of your data used.&lt;br&gt; Using [doc://split] or even [doc://substr] might probabily be better, if OPs data is known. I can only assume data here.&lt;br&gt;
&lt;code&gt;
use warnings;
use strict;

open my $fh,  '&gt;', 'outfile3.txt' or die "can't open file: $!";
open my $fh2, '&lt;', 'file1.txt'    or die "can't open file: $!";
while ( defined( my $line = &lt;$fh2&gt; ) ) {
    if ( $line =~ m{^(?&lt;matched&gt;.+?)\s+?.*?$}){
      print {$fh} $+{matched}, $/;
    }
}
close $fh2 or die "can't close file: $!";
close $fh  or die "can't close file: $!";
&lt;/code&gt;
Hope this helps.
&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-918402"&gt;
If you tell me, I'll forget.&lt;br&gt;
If you show me, I'll remember.&lt;br&gt;
if you involve me, I'll understand.&lt;br&gt;
--- Author [unknown to me]
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
995703</field>
<field name="parent_node">
995703</field>
</data>
</node>
