If anyone is using the ripit.pl port for FreeBSD, you may find this useful. I learned C++, and Java before I even knew what scripting was! I couldn't believe the awesome functionality of split(), chomp() and %hashs!!! I feel like the veil has been removed from my eyes
. Anyways, here is the script. Please comment if I am starting any bad habits. I have posted the verbose of the script as well to show how it works... It took me months to figure out how to do something useful with C++ and only a couple days with PERL 
#!/usr/bin/perl
#
# This scipt will take in commands from the prompt and will transfer all
# directories in 'pwd'. If a directory starts with "The" it will append
# it to the end of the band name. It will also use '-' as the demiliter
# unless another demilter is specified.
#
# The flow of the program is the following :
#
# 1 - take in Options from the prompt
# 2 - process directories and create variables
# 3 - process target
# 4 - copy files
# 5 - cleanup
print("Scott Muc's mp3 transfer script v0.1\n");
if ( $ARGV[0] eq "wop" ) {
$basedir = $ENV{"PWD"};
$targetdir = "/mnt/mp3/";
} else {
prompt();
}
if (chdir $basedir) {
read_dir();
parse_list();
copy_files();
} else {
print("Could not chdir to $basedir\n");
}
sub copy_files {
@band_list = keys(%band_hash);
foreach $band (@band_list) {
$fromdir = "$basedir/$band - $band_hash{$band}";
print("copying from $fromdir\n");
@bandp = split(/ /, $band);
if ( $bandp[0] eq "The" ) {
($dump, @bandp) = @bandp;
$bandp[-1] = $bandp[-1].",";
@bandp = (@bandp,"The");
} else {}
$banddir = "$targetdir/@bandp";
$destdir = "$banddir/$band_hash{$band}";
do {
print("Going to copy to $destdir\n");
print("Is the destination band directory acceptable? [y/n]");
chomp($accept = <STDIN>);
if ($accept eq n) {
print("What would you like to change the band dir to? :");
chomp ($banddir = <STDIN>);
} else {}
$destdir = "$banddir/$band_hash{$band}";
} while ($accept eq 'n');
if (-e $banddir) {
print("INFO: $banddir -- exists\n");
} else {
mkdir($banddir, 0755) || die "cannot mkdir $banddir: $!";
}
if (-e $destdir) {
print("INFO: $destdir -- exists\n");
} else {
mkdir($destdir, 0755) || die "cannot mkdir $destdir: $!";
}
chdir "$fromdir";
print("copying files ...\n");
system ("cp * \"$destdir\"");
print("copying done, deleting old files ...\n");
system("rm -rf \"$fromdir\"");
}
}
sub parse_list {
foreach $dir (@dir_list) {
@band_album = split(/ - /,$dir);
$band_hash{$band_album[0]} = $band_album[1];
}
}
sub prompt {
print("What is the root directory of the mp3's? : ");
chomp($basedir = <STDIN>);
print("Where is the root destination directory? : ");
chomp($targetdir = <STDIN>);
}
sub read_dir {
foreach $file (<*>) {
if ( -d $file ) {
print("progess : adding \\$file to worklist\n");
@dir_list = (@dir_list, $file);
} else {
print("warning : will not add \\$file to worklist since it is not a directory\n");
}
}
}
And here is the output
Scott Muc's mp3 transfer script v0.1
What is the root directory of the mp3's? : /home/mucman/tmp
Where is the root destination directory? : /home/mucman/test
progess : adding \Air - 10000 Hz Legend to worklist
progess : adding \John McLaughlin - Belo Horizonte to worklist
progess : adding \Mono Puff - Unsupervised to worklist
progess : adding \The Church - Hologram of Baal to worklist
progess : adding \The Flashing Lights - Sweet Release to worklist
progess : adding \The Loud Family - Plants and Birds and Rocks and Things to wor klist
progess : adding \Trans-Siberian Orchestra - Beethoven's Last Night to worklist
warning : will not add \linuxq3-1.7.tar.gz to worklist since it is not a directo ry
warning : will not add \ls.pl to worklist since it is not a directory
warning : will not add \mp3_trans.pl to worklist since it is not a directory
copying from /home/mucman/tmp/The Flashing Lights - Sweet Release
Going to copy to /home/mucman/test/Flashing Lights, The/Sweet Release
Is the destination band directory acceptable? [y/n]y
INFO: /home/mucman/test/Flashing Lights, The -- exists
INFO: /home/mucman/test/Flashing Lights, The/Sweet Release -- exists
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/Mono Puff - Unsupervised
Going to copy to /home/mucman/test/Mono Puff/Unsupervised
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/John McLaughlin - Belo Horizonte
Going to copy to /home/mucman/test/John McLaughlin/Belo Horizonte
Is the destination band directory acceptable? [y/n]n
What would you like to change the band dir to? :/home/mucman/test/McLaughlin, Jo hn
Going to copy to /home/mucman/test/McLaughlin, John/Belo Horizonte
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/Air - 10000 Hz Legend
Going to copy to /home/mucman/test/Air/10000 Hz Legend
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/Trans-Siberian Orchestra - Beethoven's Last Night
Going to copy to /home/mucman/test/Trans-Siberian Orchestra/Beethoven's Last Nig ht
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/The Church - Hologram of Baal
Going to copy to /home/mucman/test/Church, The/Hologram of Baal
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/The Loud Family - Plants and Birds and Rocks and T hings
Going to copy to /home/mucman/test/Loud Family, The/Plants and Birds and Rocks a nd Things
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
AVATAR#
#!/usr/bin/perl
#
# This scipt will take in commands from the prompt and will transfer all
# directories in 'pwd'. If a directory starts with "The" it will append
# it to the end of the band name. It will also use '-' as the demiliter
# unless another demilter is specified.
#
# The flow of the program is the following :
#
# 1 - take in Options from the prompt
# 2 - process directories and create variables
# 3 - process target
# 4 - copy files
# 5 - cleanup
print("Scott Muc's mp3 transfer script v0.1\n");
if ( $ARGV[0] eq "wop" ) {
$basedir = $ENV{"PWD"};
$targetdir = "/mnt/mp3/";
} else {
prompt();
}
if (chdir $basedir) {
read_dir();
parse_list();
copy_files();
} else {
print("Could not chdir to $basedir\n");
}
sub copy_files {
@band_list = keys(%band_hash);
foreach $band (@band_list) {
$fromdir = "$basedir/$band - $band_hash{$band}";
print("copying from $fromdir\n");
@bandp = split(/ /, $band);
if ( $bandp[0] eq "The" ) {
($dump, @bandp) = @bandp;
$bandp[-1] = $bandp[-1].",";
@bandp = (@bandp,"The");
} else {}
$banddir = "$targetdir/@bandp";
$destdir = "$banddir/$band_hash{$band}";
do {
print("Going to copy to $destdir\n");
print("Is the destination band directory acceptable? [y/n]");
chomp($accept = <STDIN>);
if ($accept eq n) {
print("What would you like to change the band dir to? :");
chomp ($banddir = <STDIN>);
} else {}
$destdir = "$banddir/$band_hash{$band}";
} while ($accept eq 'n');
if (-e $banddir) {
print("INFO: $banddir -- exists\n");
} else {
mkdir($banddir, 0755) || die "cannot mkdir $banddir: $!";
}
if (-e $destdir) {
print("INFO: $destdir -- exists\n");
} else {
mkdir($destdir, 0755) || die "cannot mkdir $destdir: $!";
}
chdir "$fromdir";
print("copying files ...\n");
system ("cp * \"$destdir\"");
print("copying done, deleting old files ...\n");
system("rm -rf \"$fromdir\"");
}
}
sub parse_list {
foreach $dir (@dir_list) {
@band_album = split(/ - /,$dir);
$band_hash{$band_album[0]} = $band_album[1];
}
}
sub prompt {
print("What is the root directory of the mp3's? : ");
chomp($basedir = <STDIN>);
print("Where is the root destination directory? : ");
chomp($targetdir = <STDIN>);
}
sub read_dir {
foreach $file (<*>) {
if ( -d $file ) {
print("progess : adding \\$file to worklist\n");
@dir_list = (@dir_list, $file);
} else {
print("warning : will not add \\$file to worklist since it is not a directory\n");
}
}
}
And here is the output
Scott Muc's mp3 transfer script v0.1
What is the root directory of the mp3's? : /home/mucman/tmp
Where is the root destination directory? : /home/mucman/test
progess : adding \Air - 10000 Hz Legend to worklist
progess : adding \John McLaughlin - Belo Horizonte to worklist
progess : adding \Mono Puff - Unsupervised to worklist
progess : adding \The Church - Hologram of Baal to worklist
progess : adding \The Flashing Lights - Sweet Release to worklist
progess : adding \The Loud Family - Plants and Birds and Rocks and Things to wor klist
progess : adding \Trans-Siberian Orchestra - Beethoven's Last Night to worklist
warning : will not add \linuxq3-1.7.tar.gz to worklist since it is not a directo ry
warning : will not add \ls.pl to worklist since it is not a directory
warning : will not add \mp3_trans.pl to worklist since it is not a directory
copying from /home/mucman/tmp/The Flashing Lights - Sweet Release
Going to copy to /home/mucman/test/Flashing Lights, The/Sweet Release
Is the destination band directory acceptable? [y/n]y
INFO: /home/mucman/test/Flashing Lights, The -- exists
INFO: /home/mucman/test/Flashing Lights, The/Sweet Release -- exists
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/Mono Puff - Unsupervised
Going to copy to /home/mucman/test/Mono Puff/Unsupervised
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/John McLaughlin - Belo Horizonte
Going to copy to /home/mucman/test/John McLaughlin/Belo Horizonte
Is the destination band directory acceptable? [y/n]n
What would you like to change the band dir to? :/home/mucman/test/McLaughlin, Jo hn
Going to copy to /home/mucman/test/McLaughlin, John/Belo Horizonte
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/Air - 10000 Hz Legend
Going to copy to /home/mucman/test/Air/10000 Hz Legend
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/Trans-Siberian Orchestra - Beethoven's Last Night
Going to copy to /home/mucman/test/Trans-Siberian Orchestra/Beethoven's Last Nig ht
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/The Church - Hologram of Baal
Going to copy to /home/mucman/test/Church, The/Hologram of Baal
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
copying from /home/mucman/tmp/The Loud Family - Plants and Birds and Rocks and T hings
Going to copy to /home/mucman/test/Loud Family, The/Plants and Birds and Rocks a nd Things
Is the destination band directory acceptable? [y/n]y
copying files ...
copying done, deleting old files ...
AVATAR#