JavaFan has nailed the essential problems (as he usually does), but I'll add a few more (which are admittedly less important):

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.