[tpm] Glob problem

Shlomi Fish shlomif at iglu.org.il
Tue Oct 27 11:15:39 PDT 2009


Hi arocker!

See below for my responses.

On Tuesday 27 Oct 2009 19:21:04 arocker at vex.net wrote:
> > use File::Slurp ;
> 
> A constraint I didn't specify was "use only stuff in the standard
> distribution, where possible". My powers don't extend to installing from
> CPAN, and the person who can is busy doing other things I need done.
> 

First of all, you should know that many people on the Perl blogosphere, the 
Perl IRC world, etc. have little patience for people who say "We cannot 
install anything from CPAN." See, for example, what Matt S. Trout wrote about 
it here:

http://www.shadowcat.co.uk/blog/matt-s-trout/but-i-cant-use-cpan/

Namely, you can use local::lib or whatever, etc.

That put aside, File::Slurp is a simple, self-contained wrapper for some of 
the functions in perldoc perlfunc and others in perldoc File::Spec and other 
core modules. I'm also quite fond of Ingy's IO::All which is more 
comprehensive, and has a lot of syntactic sugar, but also potentially more 
buggy and quirky. See:

http://search.cpan.org/dist/IO-All/

What I'm saying is that you can do all that using only core stuff. See:

* perldoc -f readdir 
* perldoc -f opendir
* perldoc File::Spec
* perldoc -f grep
* perldoc -f map

> > my ($file_name) = map "$from_dir\\$_", grep /${job_no}XX-.*\.txt/,
> > 		read_dir $from_dir ;
> 
> Frankly, I don't see that as any great improvement. (I put the regex value
> in a variable so I could make changes for testing purposes, without
> disturbing the selection code.)

The improvement here is conveying the meaning precisely - if you use 
File::Find people may think you want to traverse a directory recursively. You 
shouldn't pick the shortest way (you're not doing golf in production, I hope), 
but the one that is more semantically correct and/or performs better (runs 
faster, consumes less resources, etc.).

See for example:

http://en.wikipedia.org/wiki/KISS_principle

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
What Makes Software Apps High Quality -  http://shlom.in/sw-quality

Chuck Norris read the entire English Wikipedia in 24 hours. Twice.


More information about the toronto-pm mailing list