×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

peculiar problem in appending !!

peculiar problem in appending !!

peculiar problem in appending !!

(OP)
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 "$buffer"



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 , "/home/dc5/loc/uniqout.txt");
open(ONP , ">>/home/dc5/uniqout_filter.txt");
while(<INP>)
{
 $i = $_;
@arr = split(/ /, $i);
if ( $#arr eq 3) { print ONP "$arr[0] $arr[1] $arr[2] $arr[3]"; }
if ( $#arr eq 4) { print ONP "$arr[0] $arr[1] $arr[2] $arr[4]"; }
if ( $#arr eq 5) { print ONP "$arr[0] $arr[1] $arr[2] $arr[5]";}
}
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, "/home/dc5/uniq.txt");
open(OPF, ">> /home/dc5/uniqout.txt");
while(<IPF>) { $buffer .= $_}
close IPF;
$buffer =~  s/(.*?)\n(.*?)\n/$1 $2/gs;
print OPF "$buffer"

open(INP , "/home/dc5/loc/uniqout.txt");
open(ONP , ">>/home/dc5/uniqout_filter.txt");
while(<INP>)
{
 $i = $_;
@arr = split(/ /, $i);
if ( $#arr eq 3) { print ONP "$arr[0] $arr[1] $arr[2] $arr[3]"; }
if ( $#arr eq 4) { print ONP "$arr[0] $arr[1] $arr[2] $arr[4]"; }
if ( $#arr eq 5) { print ONP "$arr[0] $arr[1] $arr[2] $arr[5]";}
}
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

RE: peculiar problem in appending !!

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close