sub insert{ print "insert called:". $ins ."\n"; $ins++; my @toBeInserted = @_; print `cat $outfile`; open(FILE2,$outfile)||die "you stupid ****, file doesn't exit\n";; open(FILE3,">"."tmp.file")||die "you stupid ****, file doesn't exit\n";; my $cnt=0; while (){ chomp; my @fields = (split /[ \t]+/,$_); push(@fields,$toBeInserted[$cnt]); foreach(@fields){ my $tmpString = $_ . "\t"; print FILE3 $tmpString; } print FILE3 "\n"; $cnt++; } close(FILE2); close(FILE3); #now swap the files unlink($outfile) || die "Cannont delete old file.\n"; rename("tmp.file", $outfile) || die "Cannot rename file\n"; print `cat $outfile`; }