in reply to case insensitive filename matching
this code:test ->trEE ->/A ->/b
prints: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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: case insensitive filename matching
by Preceptor (Deacon) on Feb 14, 2005 at 10:22 UTC |