[tpm] Glob problem

Uri Guttman uri at StemSystems.com
Tue Oct 27 09:07:32 PDT 2009

>>>>> "LREQ" == Liam R E Quin <liam at holoweb.net> writes:

  LREQ> On Tue, 2009-10-27 at 11:21 -0400, Uri Guttman wrote:
  >> use File::Slurp ;
  >> my ($file_name) = map "$from_dir\\$_", grep /${job_no}XX-.*\.txt/,
  >> read_dir $from_dir ;

  LREQ> Oh, that read_dir, I thought you meant readdir() and opendir(), the
  LREQ> built-in posix functions.

either one. slurp's read_dir saves you the open/close call and the
dirhandle variable so it is somewhat cleaner. and it already greps out
. and .. for you (not needed in the example i showed). if/when i add
those new options, it would be even better.

the prefix_dir option is interesting as that is a common bug when
reading dirs (but not always with globbing) as dirs only contain the
file name and not the path to that dir. so you need to prefix the dir
when opening the file (unless you are chdir'ed there already). the
option would remove the need for the extra map call to do the prefixing
(easy enough but redundant in the use of the dir path). one issue is
needing to use file::spec to merge the parts vs a simple join on
'/'. file::find has a global with the full path to the file that you can
use for this.

  LREQ> File::Find is included with perl-base here and File::Slurp isn't
  LREQ> installed here, but otherwise I don't have strong feelings.

slurp is on cpan. some think it should be in the core but p5p
doesn't. lobby for it to be in core if you can! :)


Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

More information about the toronto-pm mailing list