![]() |
|
Just another Perl shrine | |
PerlMonks |
Distribute MP3 recordings optimally to CD-Rsby Brutha (Friar) |
on Sep 30, 2005 at 11:34 UTC ( #496388=CUFP: print w/replies, xml ) | Need Help?? |
After collecting lots of MP3 recordings of radio audio-plays, I think it is time to clean up my harddisk and burn them to CD-Rs. Of course, I want to fill each CD as much as possible. Task for the Perl programm is, to tell me which files I have to burn together on one CD-R.
The 'du' command gives me a list of file/directory sizes, which I clean up manually, that is drop subdirectories etc. This list is read into a list called @files, which contains pairs of size and name. I sort this one, for the biggest directories first. Now I call my little subroutine TrySolution, which finds out the combinations of files sums up to the closest value of space available on a CD-R. The solution is thrown out of the @files list and TrySolution is started again for the next solution as long as entries are left in @files. Sounds easy, but do you remember all those nifty algorithms from your university times and do they fit? I didn't, but this was a nice exercise. The solution is still not optimal, but reasonably fast, e.g. you could stop the recursive call, if you can exclude impossible branches. And it was fun. But when I finished and was proud about the fantastic combinations found, I suddenly recognized, that I asked the wrong question. I asked for filling each CD to a maximum, I should have asked to fille as little CDs as possible. But that is another question ;-) Read below for the main parts of my script:
And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: "Psst!"
Back to
Cool Uses for Perl
|
|