[comp.lang.perl] which for msdos perl

stergios@portia.Stanford.EDU (Stergios) (06/22/91)

here's a unix which like thingy for msdos perl.  Hope this is the
right place for it.

I never could get file globbing [ <soempathhere> ] 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] <files to find>\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