On Tue, Oct 22, 2002 at 10:13:49PM +0200, K Pfeiffer wrote: > My "if" loop
"if" isn't a loop, it's a conditional. > didn't work with "last" so I changed "if" to "while", but it > seems that the "redo" doesn't cause the "while" to re-evaluate with the new > value of $destfile. This is the documented behaviour of redo. The first sentence of perldoc -f redo: The "redo" command restarts the loop block without evaluating the conditional again. > When I run this and type something other than "yes" I get the message > "File foobar already exists..." (even though 'it don't') > > while (-e $destfile) { > print "$destfile exists. Enter new name or type \"yes\" to overwrite: "; > chomp ($_ = <STDIN>); > last if $_ =~ /yes/i; > $destfile = $_; > redo; > } Why are you using redo here? "while" is a loop, it naturally, uh, loops. You don't need to tell it to loop again. Just let it fall through. Also, given your regex, if the person typed in, say, 'yesterdays.txt' your program would think they had typed in 'yes'. You might want to change it to: last if lc($_) eq "yes"; > perldoc -f redo says '"redo" cannot be used to retry a block which returns a > value...'; that I've learned, but maybe someone can suggest a better way > (would that be 'use a subroutine'?)... Why is this restriction of redo a problem? It seems like you're following up from a previous post, but I don't recall it, so I don't have any context to your question, or your intent. Given your misunderstanding of basic Perl syntax you might want to get your hands on some basic learning material, such as _Learning Perl_ or _Beginning Perl_. See learn.perl.org for more references. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]