Real-Time TextIO

Posted on 2002-03-05
Last Modified: 2010-03-05

I need to be able to write text into a file immediately, however, I notice that all of my writing is being done at the end of my program.

I've tried closing and re-opening my file pointer but that doesn't work.

    open (LOG_FILE,">>./AUTO_LOG/AUTO_v1_0.log");
    print LOG_FILE ("\nStuff...\n");
    close (LOG_FILE);

How do I immediately force text out to a file?

Thanks in advance,
Question by:Alex_Tong
  • 2
LVL 19

Expert Comment

by:Kim Ryan
ID: 6843220
You need to turn the buffering off at the start of your script

$| = 1;

LVL 16

Expert Comment

ID: 6843450

Welcome back!!

You have the following question open for a long time now. Please take some time to close this question.

EE userid Alex_Tong
Total questions asked 29 (100%)
Open questions 1
Topic Area              URL              Date              
C Programming   02/16/01  

Your help in closing this question will be highly appreciated.


(NOT a moderator at EE)

Accepted Solution

japhyRPI earned 50 total points
ID: 6843548
teraplane was close, but you need to turn off buffering for the filehandle(s) you need, via the select() function:

  open LOGFILE, ">> logfile" or
    die "can't append to logfile: $!";
    my $oldfh = select LOGFILE;
    $| = 1;
    select $oldfh;
  # ...
LVL 16

Expert Comment

ID: 6845649

Thank you for taking the time to close the open question.

Your help is highly appreciated.

(NOT a moderator at EE)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Input from stdin for perl 6 118
Perl Sort Question 4 129
Ned Perl Snippet to Read Files in Directory 5 62
create a gui in perl 3 72
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now