QUOTE(dsherohman @ 18 Jun, 2009 - 04:59 AM)

I'm not a golfer, but the first thing that came to mind is that your array (@a) is completely unnecessary and doesn't serve any obvious purpose beyond making the code longer.
CODE
$c=0;
while(`ls -F` =~ m/(\S.*\.jpg)/g) {
rename $1,"pic$c.jpg" unless (-e "pic$c.jpg");
$c++;
}
is exactly equivalent, without going through the trouble of building and reading from the array.
This can be further tightened up by looking at KevinADC's version, but note that his doesn't include the protection against clobbering existing files.
I actually tried that (I think). My problem is that `ls -F`, as well as the dir command I use for windows, lists them alphabetically. so let's say there are 3 pictures titled:
CODE
apple.jpg
car.jpg
duck.jpg
After the first iteration of the loop, the files are as follows (In alphabetic order - because that's how
ls -F will show them)
CODE
car.jpg
duck.jpg
pic0.jpg
The first iteration found the first file and changed it. In the next iteration, the while loop will find the second file, which is now duck.jpg and not car.jpg, and change it.
CODE
car.jpg
pic0.jpg
pic1.jpg
During the last iteration, the script will look at pic1.jpg, but not change it b/c I told it not to. (This prevents a file overwriting a file that already exists).
@KevinADC
Now, let's say I want to all of the files that are something like "auto.*" (like auto.jpg, auto.txt, etc) and change them to "car.*" Could I just change your script to
for <auto.*>? I realize I would have to change the regular expression a bit to store the file extension in $2 or something, but I'm more curious about the for loop.