At 11:28 AM 12/10/01 -0600, Booher Timothy B 1stLt AFRL/MNAC wrote: >I want to be able to rename a file name from one number series to >another number series ie: > >Image1.jpg >Image2.jpg >Image3.jpg >.... > >to > >Foo234.jpg >Foo235.jpg >Foo236.jpg >.... > >Is there a way to do this using regular expressions? Is there a more elegant >way to adding a counter to the script above and hard-code the argument?
Quick-n-dirty: for (glob("Image*.jpg")) { /(\d+)\./ and rename $_, "Foo$1.jpg"; } A bit more flexible: # my_rename("Image", "Foo"); sub my_rename { my ($from, $to) = @_; for (glob("$from*.jpg)) { /(\d+)\./ and rename $_, "$to$1.jpg"; } } Even more so: # my_rename('Image(\d+).jpg', 'Foo$1.jpg'); sub my_rename { my $from = qr/^$_[0]$/s; for (glob "*") { next unless /$from/; my $to = eval qq("$_[1]"); rename $_, $to unless -e $to; } } Watch that the backslashes get passed through properly, and be aware that glob() can have trouble with large result sets pre-5.6. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]