D
ddtl
Hello everybody,
I wrote a perl script, which is supposed to rename music files : you
pass it a directory name to use, regexp to search for
(let's call it searchexp) and a replacement regexp (let's call it
repexp).
It reads filenames from the directory, processes filenames by
replacing searchexp by repexp, and renames the files.
What i don't understand, is why sometimes you pass a searchexp that
matches filename, but a script won't replace it with repexp.
Here is a relevant problematic code snippet ($opts{'s'} holds
searchexp, and $opts{'r'} - repexp. $i and $n are variables
incremented
by the loop):
1) @entry = fileparse($dir_list[$i], @extensions);
2) # if extension is not .mp3, .ogg or similar - no need to process
3) if ($entry[2] eq "") {next;}
4) $name_before[$n] = "$entry[1]" . "$entry[0]" . "$entry[2]";
5) $entry[0] =~ s/\Q$opts{'s'}\E/\Q$opts{'r'}\E/g;
6) $name_after[$n] = "$entry[1]" . "$entry[0]" . "$entry[2]";
7) $n++;
For example, if i have one file named '00.mp3' in a directory,
searchexp is "[\d]{2}" and repexp is "a" (without surrounding
brackets,
of course) - after execution of a line
5, $entry[0] is still "00", as before (i checked (using debugger) that
$opts{'s'} and $opts{'r'} really had a values of "[\d]{2}" and "a",
respectively, and that value of "$entry[0]" didn't change after
execution
of a line 5).
What is wrong here? What is still stranger, is that sometimes script
does works as it should (for example, if filename is "_0_0.mp3",
searchexp "_" and repexp "a").
ddtl.
I wrote a perl script, which is supposed to rename music files : you
pass it a directory name to use, regexp to search for
(let's call it searchexp) and a replacement regexp (let's call it
repexp).
It reads filenames from the directory, processes filenames by
replacing searchexp by repexp, and renames the files.
What i don't understand, is why sometimes you pass a searchexp that
matches filename, but a script won't replace it with repexp.
Here is a relevant problematic code snippet ($opts{'s'} holds
searchexp, and $opts{'r'} - repexp. $i and $n are variables
incremented
by the loop):
1) @entry = fileparse($dir_list[$i], @extensions);
2) # if extension is not .mp3, .ogg or similar - no need to process
3) if ($entry[2] eq "") {next;}
4) $name_before[$n] = "$entry[1]" . "$entry[0]" . "$entry[2]";
5) $entry[0] =~ s/\Q$opts{'s'}\E/\Q$opts{'r'}\E/g;
6) $name_after[$n] = "$entry[1]" . "$entry[0]" . "$entry[2]";
7) $n++;
For example, if i have one file named '00.mp3' in a directory,
searchexp is "[\d]{2}" and repexp is "a" (without surrounding
brackets,
of course) - after execution of a line
5, $entry[0] is still "00", as before (i checked (using debugger) that
$opts{'s'} and $opts{'r'} really had a values of "[\d]{2}" and "a",
respectively, and that value of "$entry[0]" didn't change after
execution
of a line 5).
What is wrong here? What is still stranger, is that sometimes script
does works as it should (for example, if filename is "_0_0.mp3",
searchexp "_" and repexp "a").
ddtl.