At 11:31 AM 12/11/01 -0600, Booher Timothy B 1stLt AFRL/MNAC wrote:
>Over the last evening I have reviewed these scripts and understand what is
>going on, but they still don't quite solve my problem. I want to fix the
>following situation.
>
>Image4.jpg, image5.jpg, image6.jpg - to --> foo78.jpg, foo79.jpg, foo80, etc
>.. ..
>
>This means I want to change the number not just the word involved. So for
>example I would want to give the parameter StartAt: '78' and 's/image/foo' -
>say I wanted to start at any arbitrary number given another arbitrary
>number, by specifing the offset (here 74). This is what I am having trouble
>doing

Ah, okay, missed that part.  Here's a couple of solutions.  This one makes 
the second parameter a string containing a Perl expression:

# my_rename('Image(\d+).jpg', '"Foo" . ($1+74) . ".jpg"');
sub my_rename {
    my $from = qr/^$_[0]$/s;
    for (glob "*") {
      next unless /$from/;
      my $to = eval "$_[1]";
      rename $_, $to unless -e $to;
    }
}

That's rather more flexible than you asked for.  If you want the offset to 
be a parameter, then it can be extended quite easily:

# my_rename('Image(\d+).jpg', '"Foo" . ($1+$_[2]) . ".jpg"', 74);
sub my_rename {
    my $from = qr/^$_[0]$/s;
    for (glob "*") {
      next unless /$from/;
      my $to = eval "$_[1]";
      rename $_, $to unless -e $to;
    }
}



--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to