#!perl -Wall # A Windows utility to mimic the functionality of 'which' under most Unix systems. my @path=split(";",`echo %PATH%`); # This list of executable extensions must be provided explicitly # as no feature exists in Windows. # I based this list on http://antivirus.about.com/od/securitytips/a/fileextview.htm my @ext = qw{exe bat com wsh pl ade adp bas cd cmd cpl crt dll hlp hta inf ins js jse lnk mdb msc msi ocx pif reg scr sct shs sys url vb vbe vbs wsc wsf}; # Remove the final path entry if it doesn't exist. # Some paths end in ; which causes this error pop @path if $path[-1]=~//; # Seach each path in order, as DOS does, to find the command. foreach(@path) { my $stem = "$_\\$ARGV[0]"; # add slash because not all paths end in one, and double slash is acceptable foreach(@ext) { if (-e "$stem.$_"){ print "$stem.$_"; # The traditional version of which exits after the first successful # find. To save parsing arguments (like -a) we do the same. # p.s. note the return values match the POSIX conformant values. exit (-x "$stem.$_") ? 0 : 1; } } } 1;