Let's break it down. We'll assume for the sake of simplicity that Algorithm::BinPack does what it says and that we don't need to test that. So the things you need to test are:
  1. Does the mkdir create the directory you want for the output?
  2. Does the while loop find all the files in the directory you're backing up?
  3. Does the list of files per bin look right?
You can't test any of those as the code is currently organized because the logic's all in line. If you wanted to be able to test this (and you should want to; you're depending on it to back up your data!), you'll need to reorganize it so it's testable.

It's not necessary to go all the way to a separate package; you can get away with wrapping the functions in subs and then modifying your main-line code to call them. You can then add a way to run a test vs. doing a backup via Getopt::Long or an environment variable. (Personally I'd spend the time to create the package simply because I could leverage Perl's build-and-test infrastructures.)

On a cursory scan, I think this

$dir or die "Can't mkdir $dir: $!";
doesn't do what you think it does. If you qx() the string in $dir then it will be executed, but just referencing it like this, Perl will only check it to see if it's "true" (i.e., not null in this case), and will not execute it!

The while loop may work, but honestly, you need to test it to be sure that it does.

A couple other notes: what happens if one of your files is bigger than a DVD? (Right now you'll attempt to mv it and fail.)

If the subroutine wrapping seems like too much work, then you should at least create some sample directories to be backed up, figure out by inspection what should happen, and then run the script to see if it does. If you change the size of a DVD to (say) 500 bytes, you can create a few files of a couple hundred bytes each and try it out.

EDIT: typos.


In reply to Re: BinPack Algorithm Use To Pack Files In a DVD by pemungkah
in thread BinPack Algorithm Use To Pack Files In a DVD by mgrangeiro

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.