CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
perl file I/O bug ?

 



willperl42
New User

Nov 17, 2014, 1:28 PM

Post #1 of 7 (14635 views)
perl file I/O bug ? Can't Post

I recently have seen a problem when writing data to a file where a bit of data got dropped - writes before and after showed up in the file correctly. Turning on autoflush fixed the problem. Has this been seen before?


Laurent_R
Veteran / Moderator

Nov 17, 2014, 11:17 PM

Post #2 of 7 (14625 views)
Re: [willperl42] perl file I/O bug ? [In reply to] Can't Post

There is far too little information to make it possible to say anything, let alone reproduce the "bug" you mention. If your program blows away violently, it could happen that the output buffer be lost. Other than that, there are huge numbers of people using Perl IO everyday, I very much doubt that there is a bug on it.

If you want to insist that something is really wrong, please tell us which version of Perl you are using, give us the code that led to this loss of data, show your data samples, provide the conditions in which this happens, in brief, make it possible for us to reproduce the alleged bug.


willperl42
New User

Nov 18, 2014, 6:45 AM

Post #3 of 7 (14604 views)
Re: [willperl42] perl file I/O bug ? [In reply to] Can't Post

The version is v5.10.1 running on Ubuntu Linux 3.11.0-20. I was mainly wanting to ask if anyone else had seen something similar. The problem is reproducible, but providing the code and data would be difficult - the application is a log post-processor and the logs involved are proprietary and very large. I've seen the problem in only one set of logs, so reproducing it in a sanitary way would likely be too time consuming since I don't know what characteristics this log set has that differentiate it from others where I haven't seen the problem. I could provide a code snipit, but I'm not sure how much that would help - it's a pretty basic 'iterate through a hash, writing data to a file' deal.


FishMonger
Veteran / Moderator

Nov 18, 2014, 6:58 AM

Post #4 of 7 (14600 views)
Re: [willperl42] perl file I/O bug ? [In reply to] Can't Post

The problem you experienced is due to a bug in your code, not perl.

If you're willing to post the script and a sanitized sample of the log (i.e., proprietary info obfuscated), we would be willing to help you find the bug. If you do that, please try to post the section of the log file that relates to the missing data.


Zhris
Enthusiast

Nov 18, 2014, 7:20 AM

Post #5 of 7 (14595 views)
Re: [willperl42] perl file I/O bug ? [In reply to] Can't Post

Hi,

Often programmers don't close a filehandle when they have finished with it using the in built close function. Closing the filehandle will flush the IO buffer as part of its tasks. However, the only time I have noticed flush issues when not closing a filehandle is when there are layers i.e. an encoding layer, but I wouldn't rely on it automatically flushing either way:


Code
my $str = "hello\n"; 
open my $fh, '>>:encoding(UTF-8)', \$str;
print $fh "world\n";
print $str;

output:

Code
hello


Using autoflush is fine, but it will flush after every write / print. A better solution might be to use IO::Handle's flush method, which inevitably gives you more control.

Chris


willperl42
New User

Nov 18, 2014, 7:55 AM

Post #6 of 7 (14585 views)
Re: [Zhris] perl file I/O bug ? [In reply to] Can't Post

I am closing the file at the end. In any case this was data missing from the middle of the output file, so it's not immediately clear why turning on autoflush should have helped in the first place. I tried it only because I saw the data print to stdout when I duplicated the lines and removed the file qualifier.

I just went back and turned off autoflush and re-ran against the same log set and didn't see the problem. I'm at a loss at this point - before turning on autoflush, I saw the problem repeatedly.


Zhris
Enthusiast

Nov 18, 2014, 8:11 AM

Post #7 of 7 (14579 views)
Re: [willperl42] perl file I/O bug ? [In reply to] Can't Post

Ah, I understand your problem better now, data missing from the middle does indeed seem odd. As others have asked, could you possibly provide code / data that replicates your issue, that is if you can still replicate it yourself. If I find any further information I think you will benefit from, I'll be sure to post.

Chris

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives