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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

peculiar problem in appending !! 1

Status
Not open for further replies.

rao12

IS-IT--Management
Jan 10, 2001
9
0
0
US
Hi,

I have an input file with about 330 lines in it.

The input file is created as a result of this script.

script1
========

#!/usr/local/bin/perl
open(IPF, "/home/dc5/uniq.txt");
open(OPF, ">> /home/dc5/uniqout.txt");
while(<IPF>) { $buffer .= $_}
close IPF;
$buffer =~ s/(.*?)\n(.*?)\n/$1 $2/gs;
print OPF &quot;$buffer&quot;



The input file (uniqout.txt) looks like
-------------------

after 51 inserted XXX3 989
inserted 989 after 510 9898
changed 76 moved to kjkj4 09090
......................
......................
total 330 lines .

i have opened another file in append mode with the following code.


script2
=======

#!/usr/local/bin/perl
open(INP , &quot;/home/dc5/loc/uniqout.txt&quot;);
open(ONP , &quot;>>/home/dc5/uniqout_filter.txt&quot;);
while(<INP>)
{
$i = $_;
@arr = split(/ /, $i);
if ( $#arr eq 3) { print ONP &quot;$arr[0] $arr[1] $arr[2] $arr[3]&quot;; }
if ( $#arr eq 4) { print ONP &quot;$arr[0] $arr[1] $arr[2] $arr[4]&quot;; }
if ( $#arr eq 5) { print ONP &quot;$arr[0] $arr[1] $arr[2] $arr[5]&quot;;}
}
close INP;
close ONP;

If i execute script2 as a separate perl script it is able to print all the
330 lines with my requirement of four words per line in the output ( OPF) file uniqout_filter.txt


But .. if i take the same code (script2) and execute it along with (script1)in a single perl script it is giving only 256 lines in the (OPF file) uniq_filter.txt instead of 330.

combined script (script1 script2)
=======================================================
#!/usr/local/bin/perl
open(IPF, &quot;/home/dc5/uniq.txt&quot;);
open(OPF, &quot;>> /home/dc5/uniqout.txt&quot;);
while(<IPF>) { $buffer .= $_}
close IPF;
$buffer =~ s/(.*?)\n(.*?)\n/$1 $2/gs;
print OPF &quot;$buffer&quot;

open(INP , &quot;/home/dc5/loc/uniqout.txt&quot;);
open(ONP , &quot;>>/home/dc5/uniqout_filter.txt&quot;);
while(<INP>)
{
$i = $_;
@arr = split(/ /, $i);
if ( $#arr eq 3) { print ONP &quot;$arr[0] $arr[1] $arr[2] $arr[3]&quot;; }
if ( $#arr eq 4) { print ONP &quot;$arr[0] $arr[1] $arr[2] $arr[4]&quot;; }
if ( $#arr eq 5) { print ONP &quot;$arr[0] $arr[1] $arr[2] $arr[5]&quot;;}
}
close INP;
close ONP;

==========================================================

I am confused as to what the problem may be.
please let me know where the problem is.

Thanks for the patience

Rao
 
In the combined scripts you should probably
close OPF before you open INP. Ther may be
output buffered that has not been written out
to the file yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top