in reply to Mass file renaming
Seems you want to break the names into three chunks with the prefix and suffix retaining their original values and the middle chunk incrementing every time a new suffix sequence starts.
That being the case something like this should work:
use strict; use warnings; my $prefix; my $midCount; my $lastSuffix; while (<DATA>) { chomp; my $oldName = $_; $prefix = substr $_, 0, 3 if ! defined $prefix; my $suffix = substr $_, -2; ++$midCount if ! defined ($lastSuffix) or $suffix <= $lastSuffix; $lastSuffix = $suffix; my $newName = sprintf ("%03s%06d%02d", $prefix, $midCount, $suffix); print "$oldName -> $newName\n" }
__DATA__ 22200010001 22200010101 22200010102 22200010103 22200010201 22200010001 -> 22200000101 22200010101 -> 22200000201 22200010102 -> 22200000202 22200010103 -> 22200000203 22200010201 -> 22200000301
|
|---|