in reply to Re: Help with Space Efficency algorithim
in thread Help with Space Efficency algorithim
How can I tell how much free space is used in a list of directories?
use Cwd; use constant LIMIT => 4 * 1024 * 1024 * 1000; my @dirs; # perhaps found with File::Find for my $dir (@dirs) { my $avail = LIMIT - dir_size($dir); print "'$dir' has $avail free\n"; } sub dir_size { my ($dir) = @_; my $orig_dir = getcwd; chdir '$dir' or die "Unable to chdir to '$dir': $!"; open(my $dh, '.') or die "Unable to open a dir handle for '$dir': +$!"; my $size; while (<$dh>) { next if ! -f $_; $size += -s $_; # could use _ shortcut } chdir $orig_dir or die "Unable to restore dir to '$orig_dir': $!"; return $size; }
If, on the other hand, the packages are all available up front - I too would recommend a "good enough" algorithm rather than finding the perfect solution.
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Help with Space Efficency algorithim
by MidLifeXis (Monsignor) on Dec 27, 2007 at 20:26 UTC | |
by dragonchild (Archbishop) on Dec 27, 2007 at 21:06 UTC | |
by MidLifeXis (Monsignor) on Dec 27, 2007 at 23:17 UTC | |
by dragonchild (Archbishop) on Dec 28, 2007 at 04:32 UTC | |
|
Re^3: Help with Space Efficency algorithim
by jkhunt (Initiate) on Dec 28, 2007 at 15:56 UTC | |
by Limbic~Region (Chancellor) on Dec 28, 2007 at 18:33 UTC |