goto???
- From: shiping@xxxxxxxxxxxxxxxx (Shiping Wang)
- Date: Fri, 27 Oct 2006 16:47:03 -0500
Hello, I try to use following code to check if a file is already exist, if it exists, then ask user to change file name or override it. I know using 'goto' is not preferred way here, but what's the 'right way' to do so?
Thanks,
Shiping
-------------------------------------------------------------------------------------------------------------------------------------------
my $file = "sumpower\.txt";
if (-e $file ){
warn "The summary file already exist! Wold you like to give another name? (y/n)\n".
"If your answer is 'n' then the file will be overrided. What's your decision?\n";
STARTOVER:
my $answer = <STDIN>;
if ($answer =~ /y/i){
print "What's the new file name?\n";
$file = <STDIN>;
}elsif ($answer =~ /n/i){
unlink $file;
}else {
print "You have given a invalid answer, try again (y/n)\n";
goto STARTOVER;
}
}
open(OUT, "> $file") or die "Cannot open $file - $!";
.
- Follow-Ups:
- Re: goto???
- From: Jay Savage
- Re: goto???
- From: John W. Krahn
- Re: goto???
- References:
- ndbm error no 28
- From: C . R .
- Re: ndbm error no 28
- From: Mumia W.
- ndbm error no 28
- Prev by Date: Re: Find all matches in a string via regex
- Next by Date: Re: goto???
- Previous by thread: Re: ndbm error no 28
- Next by thread: Re: goto???
- Index(es):