loop {
my $word = prompt '> ' ;
say $word;
}
What's the right way to make it exit
if/when instead of printing a word I press Ctrl+D?
I'm less familiar with Perl 6 than with Perl 5, but the Perl 5 method seems to work:
loop {
my $word = prompt '> ' ;
last if not defined $word;
say $word;
}
This might be more idiomatic:
while (defined my $word = prompt '> ') {
say $word;
}
(Without the defined
operator, the loop will terminate on an empty input.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With