J
jfix
hello,
I have files whose names start with "parta...." which I'd like to
rename to "n0001..." where the "a" is transformed to 1, the "b" to 2
etc. I'm pretty sure there's an easy way where you take the
character's ascii value and substract the difference plus one (like
this: asc("a") - 96 = 1, right?)
sub renameFiles {
my %part = {'a' => 1, "b" => 2, "c" => 3,
"d" => 4, "e" => 5, "f" => 6};
foreach $f (@filelist) {
$f =~ s{ ### complains about Uninitialised
### value in this line
^part(.)
}{
sprintf("n%03d", $part{$1});
}xeg;
print "$f\n";
}
}
I guess this is way too much, and it is very slow (probably evaluating
the Perl code for each match), but this is my stab, and it doesn't even
work and I don't even know why.
thanks for any help,
Jakob.
I have files whose names start with "parta...." which I'd like to
rename to "n0001..." where the "a" is transformed to 1, the "b" to 2
etc. I'm pretty sure there's an easy way where you take the
character's ascii value and substract the difference plus one (like
this: asc("a") - 96 = 1, right?)
sub renameFiles {
my %part = {'a' => 1, "b" => 2, "c" => 3,
"d" => 4, "e" => 5, "f" => 6};
foreach $f (@filelist) {
$f =~ s{ ### complains about Uninitialised
### value in this line
^part(.)
}{
sprintf("n%03d", $part{$1});
}xeg;
print "$f\n";
}
}
I guess this is way too much, and it is very slow (probably evaluating
the Perl code for each match), but this is my stab, and it doesn't even
work and I don't even know why.
thanks for any help,
Jakob.