Re: Perl gecko book examples

[email protected] (iain truskett) Mon, 28 Feb 2000 03:47:56 +1100
Newsgroups perl.riscos
Message-ID <[email protected]>
* Steve Bradburn ([email protected]) [20000227 11:37]:
> [Reposted from c.s.a.programmer]
[...]
> print "What is your name? ";
> $name = <STDIN>;
> 
> Unless I add a newline, the input isn't seen until enter the input. Adding
> a newline doesn't help with later inputs, which all appear after a correct
> word has been input blind.
> 
> Do I need to add something for the correct output on a RISC PC?

A common problem due to the buffering system used (which is,
incidentally, perfectly fine).

The solution?

----------------------------
$|++;
print "What is your name? ";
$name = <STDIN>;
----------------------------

What this does is set $| to 1 which means "don't buffer output"
(possibly even "don't buffer input or output", but I haven't got any
references to hand). Some people write it as "$| = 1", but I find $|++
to be faster to type =)

It's particularly recommended with CGI scripts (curious things may
happen if you don't turn buffering off as a fellow student found last
year when his backtick commands gave their output to Apache before perl
printed the HTTP headers thus resulting in bad headers).


cheers,
-- 
#!/usr/bin/perl -- # -- iain.                  <http://eh.org/~koschei/>
($#=q/M2VYO=VQE9,=E($%B;W9E($%L;"X*.,AT='`Z+R]E:"YO<F<O?FMO<V-H96DO'<')I
>F4^"|``/)=~y-,.|\r\n\t -&/@-d,$;=pack c,280551%015025;print unpack$;,$#