Multiple executables in path (Was: NON-SOURCE POSTINGS CONSIDERED HARMFUL!)

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Mon Jan 21 10:24:40 AEST 1991


In article <1991Jan19.105624.15369 at convex.com> tchrist at convex.COM (Tom Christiansen) writes:
> From the keyboard of brnstnd at kramden.acf.nyu.edu (Dan Bernstein):
> :Hmmm. I've always been satisfied with the speed of
> :  alias which 'echo `echo "$PATH" | tr : '\''\012'\'' | sed -e '\''s+$+/\!:1+'\'' -e '\''s:^:/.[.]:'\''` | sed '\''s:/../:/:g'\'''
> But it doesn't do the same thing as mine does, Dan.

I didn't say that it did. Yours produces a result that is useful in only
a limited problem domain, and I don't see why I should write a 35-line
script for a useless result.

> Yours is more like this:
>     for $file (@ARGV) {
> 	for $dir (split(/:/,$ENV{'PATH'})) {
> 	    print $path,"\n" if -x ($path="$dir/$file");
> 	} 
>     }
> except that it uses many more processes, runs more slowly,

I tried the Perl version and the csh version on two different machines.
The csh version uses three execs and four processes, but because tr and
sed are one tenth the size of perl, the perl version is *SLOWER*.

> and is 
> significantly more difficult to read and thus maintain.

Oh? I see ``echo path, colons to newlines, tack argument on end of line
and /.[.] on beginning, glob, trash that beginning ..,'' which makes
perfect sense. The Perl version has all these confusing parenthesization
and quoting conventions, as well as -x. What's -x? Izzat from test?
What's worse, there's no obvious linear flow through the Perl code;
``file'', for example, appears near the beginning and near the end, and
your eyes have to jump all around to trace the data flow.

So the Perl version is slower, takes more memory, and is more difficult
to read and thus maintain. Sounds like a loser to me.

> But as I said, the original code does something different: it doesn't just
> tell you which paths lead to a particular command.  Rather, it produces a
> complete list of all commands in your $PATH with more than one path to
> them,

Yay.

> except for those duplicates that are just there due to symlinks to
> the same executable and by the same name, such as /etc/foo ->
> /usr/etc/foo.  That's why the $files{$name, $dev, $ino} array is kept.  I
> doubt you can do the last part with a csh alias,

Rather than expressing your doubt, why don't you spend thirty seconds
putting together the right combination of ls, rev, and sort to eliminate
your doubt?

---Dan



More information about the Alt.sources.d mailing list