in reply to Problem with loops
for ($input eq "end")Really? It runs the loop once, setting $_ to 1 or "" depending on $input, but you aren't using $_ in your loop. It probably doesn't do what you expect it to do.
As for the second choice - afterwards you read in the input, assign it to $input, then fall out of the loop.
I'd do something like:
while (1) { local $| = 1; print "add, del, prn, end? "; my $answer = <>; chomp $answer; if ($answer eq "add") { ... } elsif ($answer eq "del") { ... } elsif ($answer eq "prn") { ... } elsif ($answer eq "end") {last;} else {print "Unknown command '$answer'\n"} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem with loops
by Anonymous Monk on Nov 26, 2011 at 01:14 UTC |