What is the right way to stop an infinite while-loop with a Term::ReadLine-readline?
Posted
by sid_com
on Stack Overflow
See other posts from Stack Overflow
or by sid_com
Published on 2010-03-19T12:54:02Z
Indexed on
2010/03/19
13:21 UTC
Read the original article
Hit count: 228
What is the right way to stop an endless while-loop with a Term::ReadLine::readline?
This way I can not read in a single 0
#!/usr/bin/env perl
use warnings;
use strict;
use 5.010;
use Term::ReadLine;
my $term = Term::ReadLine->new( 'Text' );
my $content;
while ( 1 ) {
my $con = $term->readline( 'input: ' );
last if not $con;
$content .= "$con\n";
}
say $content;
and with
last if not defined $con;
the loop does never end.
© Stack Overflow or respective owner