perl $|=1; What is this?

后端 未结 3 774
借酒劲吻你
借酒劲吻你 2021-02-01 17:48

I am learning Writing CGI Application with Perl -- Kevin Meltzer . Brent Michalski

Scripts in the book mostly begin with this:

#!\"c:\\strawberry\\perl\\         


        
3条回答
  •  花落未央
    2021-02-01 18:11

    perlvar is your friend. It documents all these cryptic special variables.

    $OUTPUT_AUTOFLUSH (aka $|):

    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; $| 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 rsh and want to see the output as it's happening. This has no effect on input buffering. See getc for that. See select on how to select the output channel. See also IO::Handle.

    Mnemonic: when you want your pipes to be piping hot.

    Happy coding.


    For the other questions:

    There is no reason that use strict; comes after $|, except by the programmers convention. $| and other special variables are not affected by strict in this way. The spacing is also not important -- just pick your convention and be consistent. (I prefer spaces.)

提交回复
热议问题