Hi, I have a number of jpegs I wanted to rename. I wrote a short script to do it but the new file name is not always generated correctly. The script should find the last letter in the filename (before the extension) and substitute it for '_a'.
If you look at the results below you'll see that 'a' and 'b' fail but 'c' worked. I don't understand why. DSC00092a.jpg -> DSC00092a.jpg a DSC00093b.jpg -> DSC00093b.jpg b DSC00094c.jpg -> DSC00094_a.jpg c DSC00095d.jpg -> DSC00095d.jpg d DSC00096e.jpg -> DSC00096e.jpg e DSC00097f.jpg -> DSC00097f.jpg f DSC00098g.jpg -> DSC00098g.jpg g DSC00099h.jpg -> DSC00099h.jpg h DSC00100i.jpg -> DSC00100i.jpg i DSC00101j.jpg -> DSC00101_a.jpg j DSC00102k.jpg -> DSC00102_a.jpg k DSC00103l.jpg -> DSC00103l.jpg l ...snip Here the script, there isn't much to it. Can anyone explain why the substitute fails? TIA Dp. #!/bin/perl # Active State 5.8.6.811 use strict; use warnings; use File::Basename; my $dir = 'D:/Temp/jpegs/thumbs/'; my @files = glob("${dir}*.jpg"); foreach my $f (@files) { (my $l) = ($f =~ /([a-z]|[a-z][a-z])\.jpg/); (my $new = $f) =~ s/$l/_a/; my $basef = basename($f); my $basenew = basename($new); print "$basef -> $basenew $l\n"; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>