I'm trying to figure out if I have written the proper code for the task I'm trying to accomplish. Anybody willing to help?
#!/usr/bin/perl; use strict; use warnings; use Algorithm::BinPack; # Defines DVD capacity as a constant in bytes use constant DVD_CAP => 4707319808; # Change to directory below my $dest = "/pas/rentals/pendbackup"; chdir $dest; system("pwd"); # Creates a directory with the current date and # stores its value in the scalar variable $dir my $dir =(mkdir(`date +%Y%m%d`),0644) or print $!; # Create a new BinPack object and set the binsize # value to the DVD capacity constant DVD_CAP my $binpack = Algorithm::BinPack->new( binsize => DVD_CAP ); print "Got here before adding items!\n\n"; # Open directory $dest to process readdir that returns # the directory entries for the directory $dest opened by opendir # map: evaluates BLOCK {(stat[7])} for each element of LIST (glob '*') # and returns the list value of each evaluation (file size). # stat[7]: identifies the size of files in bytes # glob: returns a list of filenames determined by EXPR (glob EXPR). # Add items to the bin with 'label' and 'size' using the loop # Then it closes the directory $dest my $filesize; opendir(DIR,$dest) or die "Can't open directory $dest: $!"; while (my $file = readdir(DIR)) { next if $file =~ /^\.\.?$/; # skip . and .. $filesize = map {(stat)[7]} glob "*" || die "stat($file): $!\n"; if (-f $file) { $binpack->add_item(label => $file, size => $filesize); } } closedir(DIR); # Executes the mkdir function to create the directory $dir or die "Can't mkdir $dir: $!"; my $packed_bin; my $item; for $packed_bin ($binpack->pack_bins) { print "Bin size: ", $packed_bin->{size}, "\n"; for $item (@{ $packed_bin->{items} }) { printf " %-6s %-20s\n", $_, $item->{$_} for keys %{ $item }; print " ---\n"; } } system ("mv -t $packed_bin $dir");
Please, any help is welcome! Thank you. Marco

In reply to 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.