The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

File::Path::Hashed - generate path including hash value directories

SYNOPSIS

  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.

DESCRIPTION

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.

FUNCTION

hash_path(filename => $fileame, %options)

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

base_dir

specify base(prefix) directory. File::Spec->tmpdir() is the default.

depth

specify hash subdirectory depth. 2 is the default.

  hash_path(filename => 'foo.txt', depth => 3);
  # /tmp/4f/d8/cc/foo.txt
length

specify hash subdirectory name length. 2 is the default.

  hash_path(filename => 'foo.txt', length => 4);
  # /tmp/4fd8/cc85/foo.txt
make_hash_path(filename => $filename, %option)

create hashed directory for $filename with File::Path::make_path(). Options is same as hash_path().

AUTHOR

Nakano Kyohei (bonar) <bonar@cpan.com>

SEE ALSO

File::Path