Yes there is a dependency on the $GetName value because that is what the user is going to input for the program to use as a search criteria when it scans the directory for files. The $StarCh and $EndCh are basically chapter numbers. starting and ending chapters. Each of these files that will be in the directory The files will have the chapter number within the file name somewhere. For example "Test_001.txt" will be chapter 1 file but depending on who created the files, someone could have a totally different naming convention such as "Ch 1 title 3rd edition". Something like this will throw off my whole program and thats where I need the program to be more robust. I need code to handle many possibilities. Now thinking about it, maybe there isnt a way for to actually code all possibilties. Thanks for your input and some of your suggestions does help me for what its worth. Thanks!
Using your code: my $digit_width = 4; # This isnt necessarily true every time 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 now we want to create the new file na +me # Whatever $SetName was so if $SetName = "Chapter \1" which me +ans # The new file name for the program to modify in the directory + is # to "Chapter 01.txt" for the 1st chapter file which wouldve b +een # Test_001.txt in the directory it searched in. I will then # have the code rename the file. } }

In reply to Re^2: Help with my rookie logic by rookie_monk
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.