[tpm] Glob problem

Uri Guttman uri at StemSystems.com
Tue Oct 27 08:21:58 PDT 2009


>>>>> "a" == arocker  <arocker at vex.net> writes:

  a> To clarify Uri's points, I will try to give a clear definition of the
  a> particular problem: "given the first part of a filename and a regex for
  a> the rest of it, to search a single directory for a file matching that
  a> specification, and return the complete filename, (for a transfer routine
  a> that requires the exact filename)".

  >> the amount of code and relative complexity of file::find vs a
  >> simple readdir/grep is an issue (or at least it is to me).

  a> The original glob, (which worked perfectly for local directories), was:

  a> my ($file_name) = glob $from_dir . "\\" . $job_no ."XX-*.txt";

use File::Slurp ;

my ($file_name) = map "$from_dir\\$_", grep /${job_no}XX-.*\.txt/,
		read_dir $from_dir ;


one day i will add the options to read_dir to grep and also prefix the
dir to the entries. it would then look something like this:

my ($file_name) = read_dir {prefix_dir => 1},
		qr/${job_no}XX-.*\.txt/, $from_dir ;

uri

-- 
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