perl $|=1; What is this?

后端 未结 3 727
借酒劲吻你
借酒劲吻你 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:07

    $| = 1; forces a flush after every write or print, so the output appears as soon as it's generated rather than being buffered.

    See the perlvar documentation.

    $| is the name of a special variable. You shouldn't introduce a space between the $ and the |.

    Whether you use whitespace around the = or not doesn't matter to Perl. Personally I think using spaces makes the code more readable.

    Why the use strict; comes after $| = 1; in your script I don't know, except that they're both the sort of thing you'd put right at the top, and you have to put them in one order or the other. I don't think it matters which comes first.

提交回复
热议问题