Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: how to?

On Aug 23,  8:22pm, Phil Pennock wrote:
} On 2002-08-23 at 15:59 +0000, Bart Schaefer wrote:
} > c=(*.c) o=(*.o(N)) eval 'ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}'
} (for reference, mine was:
}  print -l -- *.c(e:[[ ! -f '${REPLY%.c}.o' ]]:)
} )
} One thing that I try to avoid is building up the first list in an array.
} I keep hitting machine limits on argv, so I tend to be cautious about
} _anything_ which builds lists

Your caution is somewhat misplaced.  The glob isn't enumerated anywhere,
except internally to zsh when processing the assignment; machine limits on
argv will only come into play when an external command is involved (e.g.,
there might be a problem with the "ls ${c}" in my solution, but the spec
said "do an ls" not "do a print -l", and your solution passes exactly the
same number of arguments to "print -l --" as mine passes to "ls").

In other words, you might have reason to be cautious about anything that
*expands* a list, but just building one (i.e., array assignment) should
not be an issue unless you're hitting stacksize or memoryuse limits.

The size of the environment also has an effect -- you might try exporting
as little as possible, if you frequently hit argv limits.

} Out of curiosity: the (e::) thing builds the parse tree beforehand and
} is pretty efficient, isn't it?  I've never had cause to try it on huge
} sets of data ...

I timed your solution and mine using repeated runs on about 400 files
(after changing mine to also use the "print" builtin) and they're almost
exactly the same.  Yours uses a little more system time, mine a little
more user time (file tests vs. string manipulation, I suppose).

} Which leads to a question: how much hassle is it to have a glob modifier
} be able to duplicate the Simple Command which is calling it?

A glob modifier, just about impossible.  A precommand modifier or option,
perhaps.  The problem is, by the time the E2BIG error comes back from
execve(2), it's too late to do much except croak -- so zsh would need a
heuristic to predict whether/how to split up the arguments, so it could
be done sooner.

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

Messages sorted by: Reverse Date, Date, Thread, Author