mgrangeiro has asked for the wisdom of the Perl Monks concerning the following question:
Please, any help is welcome! Thank you. Marco#!/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");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BinPack Algorithm Use To Pack Files In a DVD
by roboticus (Chancellor) on Apr 14, 2010 at 19:02 UTC | |
|
Re: BinPack Algorithm Use To Pack Files In a DVD
by GrandFather (Saint) on Apr 14, 2010 at 22:33 UTC | |
|
Re: BinPack Algorithm Use To Pack Files In a DVD
by ikegami (Patriarch) on Apr 14, 2010 at 23:35 UTC | |
|
Re: BinPack Algorithm Use To Pack Files In a DVD
by pemungkah (Priest) on Apr 14, 2010 at 23:24 UTC |