Chon-Ji has asked for the wisdom of the Perl Monks concerning the following question:

Ok another question.... I have a C program that writes/closes a file at random intervals. Then I have this perl script that gets the size (using sysseek) of the file also at random intervals. What would happen if I use sysseek to get the size while my C program is writing to it.

Replies are listed 'Best First'.
Re: Problem with sysseek
by GrandFather (Saint) on Nov 15, 2006 at 07:24 UTC

    The sysseek documentation says:

    Returns the new position, or the undefined value on failure. A position of zero is returned as the string "0 but true"; thus sysseek returns true on success and false on failure, yet you can still easily determine the new position.

    DWIM is Perl's answer to Gödel
Re: Problem with sysseek
by ikegami (Patriarch) on Nov 15, 2006 at 07:28 UTC
    my $rv = sysseek(...); # Handle error die(...) if not $rv; # Convert "0 but true" to 0 $rv += 0; ...

    Update: Oops, initial code sample was for sysread. Fixed for sysseek.

    Update: ug, me need sleep. Applied tye's fix. Now going to bed.

      "0 but true" is, of course, true, so $rv ||= 0; does no good. (:

      $rv= 0 if 0 == $rv;

      Or, tersely

      $rv += 0;

      - tye