resistance has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Data::Dumper; my $mountpoint = '/media/sdb2'; my %filesystem; $filesystem{$mountpoint} = traverse($mountpoint); sub traverse{ my %hash; my ($folder) = $_[0]; opendir DIR,$folder; my @content = grep {!/^\.{1,2}$/} readdir DIR; closedir DIR; foreach my $entry(sort @content){ if(-f $folder."/".$entry){ $hash{lc $entry} = $entry; }elsif( -d $folder."/". $entry){ $hash{$entry}= traverse($folder."/".$entry); }else{ print $folder."/".$entry." ignoring\n"; }; }; return %hash; }; print Dumper %filesystem;
this example return "exists ccC", but how to get right case of "bbb" folder? I want to retrieve it without to read the filesystem again.$hash{aaa}{bbb}{ccc}="ccC"; if(exists $hash{lc aAa}{lc bBB}{lc CCC}){ print "exists: $hash{lc aAa}{lc bBB}{lc CCC}\n"; }else{ print "not exists\n"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: threating the filesystem structure as hash of hashes
by massa (Hermit) on Jul 13, 2008 at 12:54 UTC | |
by Anonymous Monk on Jul 13, 2008 at 17:59 UTC | |
|
Re: treating the filesystem structure as hash of hashes
by BrowserUk (Patriarch) on Jul 13, 2008 at 18:27 UTC | |
|
Re: threating the filesystem structure as hash of hashes
by jethro (Monsignor) on Jul 13, 2008 at 12:41 UTC | |
|
Re: threating the filesystem structure as hash of hashes
by pc88mxer (Vicar) on Jul 13, 2008 at 13:51 UTC |