Your flag is working and breaking you out of your while loop just fine. However, you call your dirname() sub for every image found. If you put a line like the following at the beginning of your sub, you'll see what's happening:
print "Entering sub dirname\n";
For readability, I'd get rid of the flag variable altogether by putting my test in the while condition. I also find it awkward to have a break out of the first half of an if-else with the major work in the second half. (Not wrong, just awkward.) So I'd do something like this:
sub dirname { print "Entering sub dirname\n"; my $word = "site"; my $counter = 1; my $name; do { $name = $word . "_" . $counter++; } while( -e $name); mkdir $name, 0755 or warn "Cannot make dir $name: $!"; print "$name \n"; }
Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.
In reply to Re: getting a while loop to terminate
by aaron_baugher
in thread getting a while loop to terminate
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |