File: t_renumber.pl

package info (click to toggle)
libtext-xslate-perl 3.5.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,108 kB
  • sloc: perl: 19,756; ansic: 214; pascal: 182; makefile: 9; cs: 8
file content (20 lines) | stat: -rw-r--r-- 567 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!perl -w
# re-number test files
use strict;

my $dir = shift(@ARGV) or die "Usage: $0 test-dir\n";
$dir =~ s{/$}{};
-d $dir or die "No such directory: $dir\n";

my $i = 0;
foreach my $dir (sort { ($a =~ /(\d+)_\w+\.t$/)[0] <=> ($b =~ /(\d+)_\w+\.t$/)[0] } <$dir/*.t>) {
    my $n = ($dir =~ /(\d+)_\w+\.t$/)[0];
    last if $n >= 100;

    (my $newdir = $dir) =~ s/(\d+)(_\w+\.t)$/ sprintf '%03d%s', ++$i, $2 /xmse;

    next if $dir eq $newdir;

    printf "%-36s => %-36s\n", $dir, $newdir;
    rename $dir => $newdir or die "Cannot rename $dir to $newdir: $!";
}