It looks like you are splitting up files to put on a fixed-size medium (DVD perhaps?). How important is it that your solution be optimal (i.e. minimizing the number of filesets?). If that is not an important constraint, you could build buckets on a first-come-first serve basis quite easily using
File::Find, something like this (warning: untested code)
use File::Find;
use File::stat;
our @current_bucket;
our $current_size = 0;
our $BUCKET_SIZE = 4000000000;
sub add_to_bucket {
my $size = stat($_)->size();
if ($size + $current_size > $BUCKET_SIZE) {
# reset bucket
process_bucket(\@current_bucket);
@current_bucket = ();
$current_size = 0;
}
$current_size += $size;
push @current_bucket, $File::Find::name;
}
sub process_bucket {
my $bucket = shift;
# here do things like compress the list to contain
# parent directories, etc, if you really need to do this
# then print out the list.
}
find(\&add_to_bucket, "/data");
That should help you structure your problem....
If it is important that your solution be optimal, be warned that it is a hard algorithmic problem (its a form of the partitioning problem). You could still use File::Find to get the files, but the bucket forming and processing would need to be much more complex (and probably not worth it, though not knowing your precise needs I cannot say for sure...).
Best of luck..
--JAS
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.