-
Notifications
You must be signed in to change notification settings - Fork 585
Clean-up, modernize, and add examples for $|
and autoflush
#23147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: blead
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1828,19 +1828,40 @@ Also, it's just like C<$/>, but it's what you get "back" from Perl. | |
X<$|> X<autoflush> X<flush> X<$OUTPUT_AUTOFLUSH> | ||
|
||
If set to nonzero, forces a flush right away and after every write or | ||
print on the currently selected output channel. Default is 0 | ||
(regardless of whether the channel is really buffered by the system or | ||
not; C<$|> tells you only whether you've asked Perl explicitly to | ||
flush after each write). STDOUT will typically be line buffered if | ||
output is to the terminal and block buffered otherwise. Setting this | ||
variable is useful primarily when you are outputting to a pipe or | ||
socket, such as when you are running a Perl program under B<rsh> and | ||
want to see the output as it's happening. This has no effect on input | ||
buffering. See L<perlfunc/getc> for that. See L<perlfunc/select> on | ||
how to select the output channel. See also L<IO::Handle>. | ||
print on the currently selected output channel. The default is 0. | ||
|
||
C<STDOUT> will typically be line buffered if output is to the terminal | ||
and block buffered otherwise. Setting this variable is useful | ||
primarily when you are outputting to a pipe or socket. This would | ||
come into play when you are writing to a pipe and want to see the | ||
output "live" with no buffering. | ||
|
||
B<Examples:> | ||
|
||
$| = 1; # Set autoflush for current channel | ||
$is_buf = $|; # Get the current autoflush status | ||
|
||
STDOUT->autoflush(1); # Enable autoflush for STDOUT | ||
STDERR->autoflush(0); # Disable autoflush for STDERR | ||
|
||
B<Warning:> C<$|> tells you only if you have asked Perl explicitly to | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't exactly what the previous comment was saying. It is saying that the channel may be buffered or not, if it is not buffered already then autoflush won't have any effect but it still defaults to 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was worded weird originally which is why I tried to clean it up. I'm not sure what the correct less-wordy verbiage should be?
"Warning: External to Perl, the system may buffer a channel. If the system is not buffering a channel, then setting autoflush will not have any effect." ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think rather than a warning, this statement is meant to be informational: the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps it would be better to have this information in the same place where it discusses the usual buffering of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I was not being precise in saying autoflush won't have any effect on an unbuffered stream; Perl will still flush the handle after each write, it just won't make a difference because it wasn't being buffered anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The more I re-read this the more I think it was just informational. Personally I didn't think about the system buffering a channel, so knowing that setting autoflush in Perl may not always do what you want seems appropriate to me. I think my wording here is ok-ish? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current wording in the commit is not useful information. The only reason to turn on autoflush is because the channel may be buffered. |
||
flush after each write. It is still possible the channel may be buffered | ||
by the system. | ||
|
||
Mnemonic: when you want your pipes to be piping hot. | ||
|
||
B<See also:> | ||
|
||
=over | ||
|
||
=item * L<perlfunc/select> to pick the output channel. | ||
scottchiefbaker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
=item * L<IO::Handle> for more fine grained IO control. | ||
|
||
=item * L<perlfunc/getc> for information on I<input> buffering. | ||
|
||
=back | ||
|
||
=item ${^LAST_FH} | ||
X<${^LAST_FH}> | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.