Puma
P e r l   U n i v e r s a l   M a r k u p   D o c u m e n t a t i o n
SourceForge.net Logo

Puma::Util::FileSystem
This package provides functions for dealing with the Unix filesystem.
LS() AND FILESTAT()
The ls() function returns a hashtable of files for a given path.
   use Puma::Util::FileSystem qw( ls );
   use Data::Dumper;

   my $list;
   $list = ls('.', '-rf', 'FileSystem.pm');
   print Data::Dumper->Dump([$list], ['list']) ."\n";
produces the output:
   $list = {
      'FileSystem.pm' => {
         'path' => '.',
         'rdev' => 0,
         'blocksize' => 4096,
         'gid' => 100,
         'dev' => 770,
         'name' => 'FileSystem.pm',
         'blocks' => 8,
         'ctime' => 1013371680,
         'numlink' => 1,
         'mode' => 33188,
         'mtime' => 1013371680,
         'size' => 2675,
         'type' => 'file',
         'inode' => 664091,
         'uid' => 500,
         'atime' => 1013372398
      }
   };
The parameters for the ls() functions are path, flags and filefilter with path being the only required parameter.
The flags available are -r for recursive listing to tell the ls() function to recurse into any found directories and return nested hash tables for those directories. The -f flag tells ls() to flatten the recursed directories into a single hash.
The filefilter is a regular expression of files to list in a directory. Note that the filefilter will also affect which directories ls() will recurse into (that may change with future releases)
The hash that is returned for each file consists of the filename, path, filetype (dir or file) and a hashtable representation of the standard Perl stat() function. The hashtable representation of stat(function) is created by the filestat() function which is also a part of the Puma::Util::FileSystem package.
CLEANPATH()
The clearPath() utility takes a path and cleans it up, removing any extra slashes and 'dot directory' references. It makes it easier to build up paths programmatically without having to do extensive checking for these types of things.
   use Puma::Util::FileSystem qw( cleanPath );

   my $path = '/foo//bar/.././test.foo';
   print "cleanPath:\n\t$path\n\t". cleanPath($path) ."\n";
produces the output:
   cleanPath:
      /foo//bar/.././test.foo
      /foo/test.foo