Others have suggested to unbuffer your writes, but unbuffered
writes often make that your program is accessing the disk
far more often, slowing down the entire box.
Instead of using '-s', you can find the length of the file
also by seeking to the end, then using tell. No unbuffering
needed. Here's an example program:
#!/usr/bin/perl
use strict;
use warnings;
use Fcntl qw /:seek/;
my $file = "/tmp/flup";
open my $fh => "> /tmp/flup" or die;
print $fh "Some line of text\n";
my $l0 = -s $file;
# General concept, assuming the filepointer can be anywhere.
# If you know the file pointer is at the end, a simple tell()
# will do, and no seeking at all is necessary.
my $old = tell $fh or die "tell: $!";
seek $fh, 0, SEEK_END or die "seek: $!";
my $l1 = tell $fh;
die "Nothing in file!\n" unless $l1;
seek $fh, $old, SEEK_SET or die "seek: $!";
print "-s $file: $l0. seek: $l1\n";
__END__
-s /tmp/flup: 0. seek: 18
Abigail
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.