I'm processing some data an printing the results to a file. The data is taking me several days to process and I want to 'cat' the file periodically to check that file contents are okay.

I'm using 'open' to write to the file but I'm not seeing any data in the file when I know there should be. I know I'm getting the correct output because when I print to the screen and not the file, I see all the data without a problem.

As far as I understand "open" just does buffered write. Is this why I'm not seeing any data in my file yet?

Is there a way to unbuffer open?

Is syswrite the only way to do an unbuffered write?


Here's my code, I'm comparing each gps point in one file to each gps point in a second file. I'm saving each set of file points that are within 1000 feet to a file.
#!/usr/bin/perl -w use Geo::Distance; use Text::CSV_XS; my $geo = new Geo::Distance; open FIRST, "</gps/gpspoints.csv" or die "Couldn't open: $!"; my $csv = Text::CSV_XS->new({ 'quote_char' => '"', 'escape_char' => '"', 'sep_char' => ',' }); open(DAT,">/gps/datapoints.csv") || die("Cannot Open File"); while( my $first_file_line = <FIRST>){ if ($csv->parse($first_file_line)) { . my ($lon2, $lat2) = $csv->fields; open SECOND, "</gps/newdataponts.csv" or die "Couldn't open: $!"; while( my $second_file_line = <SECOND>){ if ($csv->parse($second_file_line)) { ($lat, $lon) = $csv->fields; $distance = $geo->distance( 'foot', $lon,$lat => $lon2,$lat2 ); if ( $distance < 1000 ) { print DAT "$lat2, $lon2, $lat, $lon, $distance \r\n"; } }} close SECOND; } else { my $err = $csv->error_input; print "parse() failed on argument: ", $err, "\n"; } } close FIRST; close DAT;

In reply to open - Unbuffered Write??? by awohld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.