#!/usr/bin/perl

if ($#ARGV != 1) {
	print q{\nUsage: Takes two text files, the first containing current filenames
and the second containing desired filenames, one per line.

The files must be listed in the same order in each input file.

e.g. File1:
1.mp3
2.mp3
...

File2:
01  Artist - Title.mp3
02  Some Other Artist's - Song.mp3
...

mvlist File1 File2

outputs:

mv -i '1.mp3' '01  Artist - Title.mp3'
mv -i '2.mp3' '02  Some Other Artist'"'"'s - Song.mp3'
...

Then, if you think the output looks right, you can execute it by doing:
mvlist File1 File2 > do
. do
(This is deliberately cumbersome because if you made a mistake in File1
or File2 you could do something stupid.)
};

	exit;
}

($inlist,$tolist) = @ARGV;

$in = $inlist;
$to = $tolist;
$in =~ s/'/'"'"'/g;
$to =~ s/'/'"'"'/g;
if (`wc '$in' | gawk '{print \$1}'` ne `wc '$to' | gawk '{print \$1}'`) {
	print STDERR "Error: filename lists must be the same number of lines.\n";
	exit;
}

open(IN,$inlist) or die("cannot open $inlist\n");
open(TO,$tolist) or die("cannot open $tolist\n");

while (($in = <IN>) && ($to = <TO>)) {
	chomp $in;
	chomp $to;
	$in =~ s/'/'"'"'/g;
	$to =~ s/'/'"'"'/g;
	print "mv -i '".$in."' '".$to."'\n";
}
