in reply to Term::ReadLine behaviour on a blank line
while (defined($filename = $term->readline('>'))) {
Update: While you do need to check if the returned value is defined (as opposed to just false), what I suggested is not enough to fix your program. I re-read your post, and you want to read until you get a valid file name. Why then is your loop terminated when there is nothing to read? Try this:
</c>use Term::ReadLine; # Direct notation recommended over indirect notation. my $term = Term::ReadLine->new('test'); for (;;) { $filename = $term->readline('>'); die("Unable to read in filename\n") unless defined $filename; print "checking for $filename...\n"; last if -e $filename; print "File not found. Please try again\n"; } print "filename is ~~$filename~~";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Term::ReadLine behaviour on a blank line
by Anonymous Monk on Apr 03, 2006 at 16:41 UTC |