test
->trEE
->/A
->/b
####
use strict;
use warnings;
# hash for file-system data
my %tree;
#build a datastructure that represents directory tree
#for everything below "/test"
build_tree ("/test", \%tree);
# get realpath of "c:/test/tree/a/b"
my $p = getRealPath ("TREE/A/B", \%tree);
print $p;
sub build_tree
{
my $dir = shift;
my $ref = shift;
my $dirh = shift;
opendir $dirh, $dir or die $!;
while ( $_ = readdir ($dirh) )
{
next if /^\./;
next unless -d "$dir/$_";
$ref->{subdirs}->{lc($_)} = { name=>$_, subdirs=>{} };
build_tree ("$dir/$_", $ref->{subdirs}->{lc($_)});
}
closedir $dirh;
}
sub getRealPath
{
my @path = split ("/", shift);
my $ref = shift;
my $path = "";
for ( @path )
{
$path .= "/" . $ref->{subdirs}->{lc($_)}->{name};
$ref = $ref->{subdirs}->{lc($_)};
}
return $path;
}
##
##
test/trEE/A/B