There's nothing inside your "while" loop that changes the value of $GetName, yet every iteration of your loop checks whether the value of $GetName contains an open paren. You could just check for this once, before going into the loop.
The inner "for" loop checks whether the numbers "1" through "12" occur in the current file name, but the way you're doing it, a file name containing "21" will match on two iterations (because it contains "1" and "2") and a name containing "1123" will match five times ("1", "2", "3", "11" and"12").
There seems to be a dependency between the value of $GetName and the values of $StartCh and $EndCh, but I'm not sure how these are related, exactly. If you can clear that up, things might make more sense.
If you are dealing with file names that use fixed-width digit strings with leading zeros, you might want to use a regex that checks for a specific number of digits between non-digit characters -- for example, if you're looking for file names in the range "test_0001.txt" through "test_0012.txt":
my $digit_width = 4; my $min = 1; my $max = 12; my $prefix = "test_"; my $ext = ".txt"; while ( my $file = readdir DIR ) { next unless ( $file =~ /^ $prefix (\d{$digit_width}) $ext $/x ); if ( $1 >= $min and $1 <= $max ) { # we have a match... now what? } }
In reply to Re: Help with my rookie logic
by graff
in thread Help with my rookie logic
by rookie_monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |