| File::Path::Hashed - generate path including hash value directories |
File::Path::Hashed - generate path including hash value directories
use File::Path::Hashed qw/ hash_path make_hash_path /); # create path string my $path = hash_path( filename => 'foobar.txt', base_dir => '/tmp/test', depth => 3, ); # returns "/tmp/test/fq/kj/a8/foobar.txt" # create path with File::Path::make_path my $path = make_hash_path( filename => 'foobar.txt', base_dir => '/tmp/test', depth => 3, ); # returns "/tmp/test/fq/kj/a8/foobar.txt" # and directory "/tmp/test/fq/kj/a8/" is created.
When you have to create 10000 files on your local disk or on servers, It takes time very much to seek files. In such case you had better create subdirectries to reduce the number of the files in one directory.
File::Path::Hashed::make_hash_path() creates subdirectories for specified file with MD5 hash value.
returns path string for $filename. example:
my $path = hash_path(filename => 'foo.txt'); say $path; # /tmp/4f/d8/foo.txt
This pass consists of it as follows:
(BASE_DIRECTRY) + (HASH SUBDIRECTORIES) + (FILENAME)
options
specify base(prefix) directory. File::Spec->tmpdir() is the default.
specify hash subdirectory depth. 2 is the default.
hash_path(filename => 'foo.txt', depth => 3); # /tmp/4f/d8/cc/foo.txt
specify hash subdirectory name length. 2 is the default.
hash_path(filename => 'foo.txt', length => 4); # /tmp/4fd8/cc85/foo.txt
create hashed directory for $filename with File::Path::make_path().
Options is same as hash_path().
Nakano Kyohei (bonar) <bonar@cpan.com>
| File::Path::Hashed - generate path including hash value directories |