I need to enter multiple HERE-DOCs. My codes have 2 while loops. The inner loop is used to get the multi-line here-doc. But after I enter Control-D to complete one here-doc, then the inner while loop does not run again and the outer loop runs infinitely. What is the best way to fix it?
while True {
my $y = "";
my $x = 32;
while $x=$*IN.getc {
$y = $y ~ $x;
}
say "==========";
say "[$y]"; sleep 2;
}
Why would $x continue to be EOF even after I reset $x to 32? Why would EOF be stuck in $*IN ? Thank you for your help.
When you press Ctrl+D, the terminal closes the stdin stream on its end, and then when Perl 6 tries to continue to read from it, it always gets EOF.
In your program, this causes the inner
while
loop to end. You then set$x
to32
again, but at the next start of the innerwhile
loop, the$x = $*IN.getc
immediately sets it toNil
again, because the stream is still closed.