>>-----Original Message----- > From: Thomas Bätzler [mailto:t.baetz...@bringe.com] > Sent: Thursday, May 28, 2009 11:57 AM > To: beginners@perl.org > Cc: sanket vaidya >Subject: AW: Kindly explain special variable $|
> sanket vaidya <sanket.vai...@patni.com> asked: > It would be great if some of you write a simple code which has two > different outputs for $| = 0 & $| = 1 to demonstrate the difference. >Try this with different values for $| >#!/usr/bin/perl -w >use strict; >$| = 1; >for ( 1..20 ){ > print "."; >warn "!" unless $i % 5; > sleep 1; >} >print "\n"; >__END__ >HTH, >Thomas Used your code as below: use strict; $| = 1; for my $i ( 1..20 ){ print "."; warn "i = $i !" unless $i % 5; sleep 1; } This code gave some vague picture in my mind about flushing. To summarize When we write some data, the data is not written (to terminal or file) instantly, but is collected in buffer & is only written when the buffer is full. Once the buffer is full, the data is written & thereafter buffer is erased. This is known as flushing. Setting $| = 1 flushes the buffer as soon as it receives a data. So the buffer doesn't wait to collect specific amounts of data before flushing. Kindly elaborate this & correct me if I am wrong. Regards, Sanket Vaidya _____________________________________________________________________ This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netad...@patni.com and delete this mail. _____________________________________________________________________ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/