Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!stanford.edu!leland.Stanford.EDU!stergios From: stergios@portia.Stanford.EDU (Stergios) Newsgroups: comp.lang.perl Subject: which for msdos perl Message-ID: Date: 21 Jun 91 21:57:47 GMT Sender: news@leland.Stanford.EDU (Mr News) Reply-To: stergios@kt22.Stanford.EDU Organization: AIR, Stanford University Lines: 53 here's a unix which like thingy for msdos perl. Hope this is the right place for it. I never could get file globbing [ ] to work so i had to do an opendir, readir, closedir. anyone know if 4.10 is on msdos yet? sm ----------cut here----------------------------- @REM=(" perl %0.BAT %1 %2 %3 %4 %5 %6 %7 %8 %9 @goto end ") if 0 ; # a unix like "which" for dos. name this file which.bat. # # Stergios Marinopoulos # stergios@kt22.Stanford.EDU # # SYNOPSIS: which -[bs] filename... # # DESCRIPTION: which searches the current path for the files listed in filename. # Pattern search types can be changed at any point in the argument list. # The default pattern is a beginning of filename match. # # OPTIONS: # # -b prints only those files beginning with the pattern filename. # -s prints all files containing the pattern filename as a substring. die "Usage: $0 [-bs] \n" if ( $#ARGV < 0 ) ; @dirs = split (/;/, $ENV{'PATH'}) ; $patstart = "^" ; foreach $file (@ARGV) { if ( $file =~ /-s/ ) { $patstart = "" ; next ; } if ( $file =~ /-b/ ) { $patstart = "^" ; next ; } $pattern = $patstart . $file ; print "Searching for $file....\n" ; foreach $path (@dirs) { opendir (DIR, $path) || die "Could not open dir $path\n" ; grep (/$pattern/ && print ("\t$path\\$_\n"), readdir DIR ) ; close DIR ; } } @REM=(" :end ") if 0 ; -- Stergios Marinopoulos stergios@kt22.Stanford.EDU