Hi Charles John

Thank you for the help. Your explanations are straightforward.

> C.DeRykus wrote:
>>
>> On Mar 19, 8:31 pm, [email protected] (Walt Chen) wrote:
>>>
>>> I have a public disk partition shared by different users. Everyone on
>>> the host writes different temporary file from time to time. So the
>>> partition runs out of available disk space sometimes.
>>>
>>> I have a perl script to write some data to a file in this partition
>>> everyday. In several cases, the data is incomplete due to disk-full
>>> issue and i want to detect this error.
>>>
>>> I use 'print HANDLE $data' to write the data. CPAN says if the
>>> function 'print' runs successfully, the return value is true. However,
>>> it seems that no matter the data is fully written to the file, 'print'
>>> always returns true. Now I have resolved the problem by replacing
>>> function 'print' with 'syswrite'. But I wonder is function 'print'
>>> really so unfriendly to raise IO error?
>>
>> See: perldoc -q buffer
>>
>> This will explain why 'syswrite' will report error, say a
>> full disk partition, when print may not due to buffering.
>>
>> And the remedy from the above docs is to force
>> unbuffering :
>>
>>           $old_fh = select(OUTPUT_HANDLE);
>>           $| = 1;
>>           select($old_fh);
>
> As it says in the FAQ page you pointed out above that 'will flush the
> handle’s buffer after each "print()" or "write()"'.  So you still have a
> buffer, it's just that the buffer is flushed more often than normal.
>
> And as it also says in the FAQ page you pointed out above '"syswrite()"
> bypasses buffering all together'.
>
>
>
> John
> --
> The programmer is fighting against the two most
> destructive forces in the universe: entropy and
> human stupidity.               -- Damian Conway
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to