in reply to "du" to hash
The hash element with an empty string (an illegal directory name, important here) is the sum total of everything below it.use strict; use Data::Dumper; my %blocks; for (`du`) { (my $blocks, my $rest) = split; my @dirs = split /\//, $rest; my $where = \%blocks; while (@dirs) { $where = ($where->{shift @dirs} ||= {}); } $where->{""} = $blocks; } print Dumper(\%blocks);
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: "du" to hash
by splinky (Hermit) on Jul 05, 2000 at 00:36 UTC | |
by merlyn (Sage) on Jul 07, 2000 at 19:28 UTC |