failed substitution



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";
}


.



Relevant Pages

  • Re: failed substitution
    ... script should find the last letter in the filename (before the ... Here the script, ... Perl's alternation always quits when the first alternative matches so in your ...
    (perl.beginners)
  • Re: synchronizing JPEGs from different cameras?
    ... JPEGs, then I could write a simple script to sort and rename all files. ...
    (rec.photo.digital)
  • Re: Script to Rename Computer Name in Domain
    ... i looking a script to rename computer name in domain server 2003 ... To rename a computer you bind to the parent OU/Container of the computer ... you would need to also prompt for the current name. ... ' Bind to the parent OU/container of computer object. ...
    (microsoft.public.windows.server.scripting)
  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)
  • Re: rename a local group in windows 2003
    ... strComputer = objShell.ExpandEnvironmentStrings ... I tried to rename several local groups using the MoveHere method ... Didn't matter if I ran the script on the ... WinNT provider only rename domain groups, ...
    (microsoft.public.windows.server.scripting)