Others have explained the main problem; I want to point out a problem that you didn't ask about but is nevertheless present in your code.
if ($answer=~/y/i){ my $first = "bar.txt"; Edit($first); } elsif ($answer =~/n/i){ exit }
Think about what happens if the answer is "Nay", or "Go ahead, do it!" - you have either the opposite result from what you intended, or you completely fall through your tests. Consider trying something like this instead:
{ print "Do you want to continue([yn]): "; chomp(my $answer = <STDIN>); Edit("bar.txt") if $answer =~ /^y/i; exit if $answer =~ /^n/i; redo; }
My point here is that your tests should be definitive: either the user gives you input within the range that you've defined as valid, or you send him back to the starting gate. Anything else is a long walk over a short pier, code-wise.
-- Human history becomes more and more a race between education and catastrophe. -- HG Wells
In reply to Re: loop problem
by oko1
in thread loop problem
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |