Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: alt.sources.d Subject: Re: "Simple" but non-portable == useless. Message-ID: <1991Jan31.215046.8073@iwarp.intel.com> Date: 31 Jan 91 21:50:46 GMT References: <11306:Jan2817:58:5291@kramden.acf.nyu.edu> <27A5C105.1019@tct.uucp> <1991Jan30.055113.26485@convex.com> <27A72A04.3BCA@tct.uucp> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 71 In-Reply-To: chip@tct.uucp (Chip Salzenberg) In article <27A72A04.3BCA@tct.uucp>, chip@tct (Chip Salzenberg) writes: | 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... :-) OK, here's the one I wrote sorta blind (after watching the Perl code spin by without paying much detail). It prints: e: /bin/e,/usr/bin/e /usr/ucb/e mail: /bin/mail,/usr/bin/mail /usr/ucb/mail on stock Sunos4.1. Note that the links are shown separated by commas. I didn't try to get it down into as few lines as possible. I save that for .signatures. :-) I think this version is a lot clearer about what it does. But maybe that's because *I* wrote it. :-) ################################################## #!/usr/bin/perl for $bin (split(/:/, $ENV{'PATH'})) { opendir(D,$bin) || next; for $base (readdir(D)) { $_ = "$bin/$base"; next unless -x && -f _; $exec{$base} .= "$_\0"; } closedir(D); } for (sort keys %exec) { @exec = split(/\0/,$exec{$_}); next unless @exec > 1; undef %list; for (@exec) { ($dev, $ino) = stat $_; $list{"$dev $ino"} .= "$_\0"; } @vals = sort values %list; next unless @vals > 1; print "$_:"; for (@vals) { chop; s/\0/,/g; print " $_"; } print "\n"; } ################################################## Just another Perl hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/