[tpm] Glob problem

arocker at vex.net arocker at vex.net
Tue Oct 27 07:24:53 PDT 2009


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

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

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

The File::Find solution required "use File::Find;" and

my ($file_name);
my $wanted  = $job_no . "XX-.*txt";

find sub { $file_name = $File::Find:name if /^$wanted/ ; }, $from_dir;

If I had been golfing seriously, I could probably have cut that down, but
I went for clarity. Given that most of the keystrokes are specifying the
input and output, I don't see a significant difference in code or
complexity.





More information about the toronto-pm mailing list