[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

$|

can you explain what is the use of :
$| = 1;
in perl cgi program?
if I don't use it, any problem will happen?
0
mwhuen
Asked:
mwhuen
  • 3
  • 2
1 Solution
 
ozoCommented:
perldoc perlvar
                 autoflush HANDLE EXPR

                 $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 actually buffered by the
                         system  or  not;  $| tells you only whether you've
                         asked Perl explicitly to flush after each  write).
                         Note  that  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,  such
                         as  when  you  are running a Perl script under rsh
                         and want to see  the  output  as  it's  happening.
                         This has no effect on input buffering.  (Mnemonic:
                         when you want your pipes to be piping hot.)
0
 
mwhuenAuthor Commented:
In my perl cgi program, I want to create a html and write to it, as the same time, i want to display it on the web, can i use $|=1 to accomplish my job?
0
 
mwhuenAuthor Commented:
Adjusted points to 20
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
furuCommented:
Yes.

Note that browsers might not support 'streaming' HTML and they may also treat it differently. One might not start parsing the page at all before the entire page is downloaded. Others wil parse everytime a \n is encountered while others wait for <BR> og <P> etc... Netscape up to v. 4.7 does not render tables untill the entire table is downloaded while IE seems to attempt this.
0
 
mwhuenAuthor Commented:
I can't make it.

My code is :

$|=1;
....
print "content-type:text/html\n\n";
....
....
open(NEWHTML,">new.html");
print NEWHTML<<XXX;
....
....
XXX
close(NEWHTML);


I expect the new.html is displayed on the screen by this CGI program.
But, It doesn't display, though new.html is created.

0
 
furuCommented:
Of course, since there is no print to STDOUT, nothing is displayed.

Try adding

print <<XXX;
..
..
..
XXX

(i.e. print to both new.html and STDOUT).
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now