O wise ones
I'm new to Perl and have run into a bit of a roadblock on a script I'm writing that renames files in a directory. I believe the problem involves the rename command and how it is used with an array in a for loop. the program prints out all the correct values, but it doesn't perform the renaming of the file. I've also tried using the shell command mv in place of rename, but the results are the same. any help would be greatly appreciated

### #Use the unix ls command to list the jpg files in the subdirectory ### use Shell(ls); @array = ls *jpg ; ### #Set the TotFiles scalar to the value number of elements in @array ### $TotFiles = @array + 1; print "Value of TotFiles is: $TotFiles \n"; ## #create four digit padding for the frames with a for loop ## for( $loop = 0; $loop <= $TotFiles; $loop++ ) { if ($loop < 10) { $padder = '000'; } if (($loop > 10) && ($loop < '100')){ $padder = '00'; } if (($loop > 100) && ($loop < 1000)) { $padder = '0'; } if ($loop > 1000) { $padder = ''; } ## #create a new name using the padder and the loop number ## $new = "snowscene"."."."$padder"."$loop".".jpg"; print "$new \n"; $old = @array[[$loop]] ; print $old; rename ($old, $new) ; }

holli fixed formatting


In reply to renaming a list of files by gmo

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.