Path: utzoo!utgpu!cs.utexas.edu!uunet!pdn!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: alt.sources.d Subject: Re: "Simple" but non-portable == useless. Message-ID: <27A72A04.3BCA@tct.uucp> Date: 30 Jan 91 20:18:11 GMT References: <11306:Jan2817:58:5291@kramden.acf.nyu.edu> <27A5C105.1019@tct.uucp> <1991Jan30.055113.26485@convex.com> Organization: Teltronics/TCT, Sarasota, FL Lines: 49 According to tchrist@convex.COM (Tom Christiansen): >I think he was talking about my script, not Karl's. He certainly was; sorry for the misunderstanding. >Chip's \0 stuff is sure the right way to go if you're that concerned. After I posted my script, I realized that _trailing_ \0 is easier to deal with, since the simplest output format is "s/\0/\n/". But I went back to the leading \0 when I changed my output format. >I'm not sure how easy it is to discern files with \n's in them from >separate entries in Chip's output. A directory that ends in newline could go undetected. Obviously I could octalize all the names before printing them, but that takes the output loop from grep() to for(), upping the line count by three. :-) >Here are 7 lines (although I only see 5 lines of code), and it does run >pretty fast. But you cheated by omitting closedir(DIR). >Notice I don't count files linked together. Ah, that feature is useful. But your implementation skips the useful heuristic of checking st_nlinks. Here's my latest version, still only ten lines long (with closedir()), and with a better output format ("command dir1 dir2"): =============================================================================== for $dir (split(/:/, $ENV{'PATH'})) { opendir(DIR, length($dir) ? $dir : ".") || next; while (defined($file = readdir(DIR))) { $_ = "$dir/$file"; $D{$file} .= "\0$dir" unless m#/\.\.?$# || !-f $_ || !-x _ || (stat(_))[3] > 1 && $F{$file,(stat(_))[0,1]}++; } closedir(DIR); } grep(((($x = $D{$_}) =~ s/\0/ /g) > 1 && print "$_\t$x\n"), sort keys(%D)); =============================================================================== Try getting that output format from a shell script... :-) -- Chip Salzenberg at Teltronics/TCT , "I want to mention that my opinions whether real or not are MY opinions." -- the inevitable William "Billy" Steinmetz