[LA.pm] Numbering files

Ron Smith geeksatlarge at yahoo.com
Sun May 4 14:40:16 CDT 2003


I have a group of files in a directory as follows: 
file.1
file.10
file.11
file.12
file.13
file.14
file.15
file.2
file.3
file.4
file.5
file.6
file.7
file.8
file.9


How would I go about adding a leadin '0' to the files numbered 1-9 to make the files list in order like the following:

 

file.01
file.02
file.03
file.04
file.05
file.06
file.07
file.08
file.09
file.10
file.11
file.12
file.13
file.14
file.15


 

I tried the following:

 
------------snip-------------------
#!/usr/bin/perl -w
use strict;

my @nums = (1..9);
foreach my $file (glob "file*") {
   my $newfile = sprintf "file.%02d", @nums;
   rename "$file", "$newfile";
}

------------snip------------------- But, I'm only getting only one file named 'file.01' as the result. What am I doing wrong? Ron


---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/losangeles-pm/attachments/20030504/deee50d6/attachment.htm


More information about the Losangeles-pm mailing list