[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Hoaky MacPerl Regular Expression Question



On Fri, May 14, 1999 at 09:46:39AM +0000, Richard K. Moore wrote:
> 
> 5/13/99, Ronald J Kimball wrote:
>  >You're missing 'Macintosh HD'.  In particular, this code only outputs the
>  >last directory name before the file; the rest of the path is ignored.
> 
> I know; that's what Cliff asked for!   In real code you'd probably obtain
> the original file list with File::Find::find, determine the platform
> file-separator character, and do lots of things differently.  But why use a
> hammer to kill a fly?
> 
> Also- the format Chilton's asking for is not unreasonable.  If the list of
> file names is a complete directory traversal, his format shows you the full
> subdirectory tree in outline format... why repeat higher-level directory
> names on subsequent lines??  And the volume root is hardly interesting
> except perhaps as a header line in the report.   -imho.

No, your code *never* prints the higher-level directory names.  In the
example format, each path component is printed exactly once, including the
high-level directories.

In particular, consider what your code does if there are levels that
contain directories, but no files.
Try running your code with the following list:

Macintosh HD:animals:mammals:dogs:dalmatian.txt
Macintosh HD:animals:mammals:dogs:labrador.txt
Macintosh HD:animals:mammals:cats:siamese.txt


> BTW> a question... is split always to be preferred to regex??  Is it
> significantly faster?  Do you lose very much of the advantage due to the
> storage allocation that's required for the split list?

use Benchmark;
;)

It's certainly not true that split is *always* preferred to a regex.


Ronald

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org