>>>>> "LT" == Leon Timmermans <faw...@gmail.com> writes:

  >> e) When dealing with files in directories in perl5 under linux, I need
  >> 
  >> opendir(DIR,'./path/') or die "cant open ./path/\n";
  >> 
  >> my @filelist = grep { /^.+\.txt/ } readdir(DIR);
  >> 
  >> I would prefer something like
  >> 
  >> my Location $dir .= new(:OSpath<'./data'>);
  >> 
  >> and without any further code $dir contains an Array ($d...@elems) or Hash
  >> ($dir.%elems) (I dont know which, maybe both?) of File objects. If a Hash,
  >> then the keys would be the stringified .name attribute of the files.
  >> 
  >> No need to opendir or readdir. Lazy evaluation could handle most 
situations,

  LT> I agree there should be a single function that combines opendir,
  LT> readdir and closedir. Scalar readdir can be useful in some context,
  LT> but in my experience it's the less common usage of it. From a
  LT> programmers point of view lazy operation would be convenient, but from
  LT> a resource management point of view that may be a bit complicated.

as another responder mentioned File::Slurp, i want to say it contains a
read_dir function (note the _ in the name). it does a slurp of a dir and
always filters out . and .. . i have plans to have it take an optional
qr and grep the dir list for you. something like this:

        my @dirs = read_dir( $dirpath, qr/\.txt$/ );

again, i agree these functions should not be named new() as open and
readdir have more meaning. how could you tell you were opening a file vs
a dir with just open? many coders may not even know that open in p5 will
work on a dir! you just open the file and can read the raw dir data
which will likely look like garbage unless you have the correct
filesystem c structures to decode it. so you must have some way to
designate to the open/new that this is a dir.

the whole issue of portable paths is another problem but i can't address
that.

thanx,

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

Reply via email to