extproc perl -Sw use strict; my ($v, $all, $libpath, $anyext) = ('PATH', 0, 0, 0); my $usage = < 1 and $ARGV[0] =~ /^-[elaX]$/) { shift, $all = 1 if $ARGV[0] eq '-a'; shift, $anyext = 1 if $ARGV[0] eq '-X'; shift, $v = shift if $ARGV[0] eq '-e'; shift, $libpath = 1 if $ARGV[0] eq '-l'; } die $usage if @ARGV != 1 or $anyext and $libpath; my $rex = shift; $rex = qr/$rex/i; sub my_libPath_dlls { # stolen from OS2::DLL up to some extend my ($flags, @path) = (@_); $flags = 0x7 unless defined $flags; push @path, split /;/, OS2::extLibpath if $flags & 0x1; # BEGIN push @path, split /;/, OS2::libPath if $flags & 0x2; push @path, split /;/, OS2::extLibpath(1) if $flags & 0x4; # END s,([/\\]+)$,, for @path; s,\\,/,g for @path; my @dlls; push @dlls, <$_/*.dll> for @path; return @dlls; } my @found; if ($libpath) { @found = my_libPath_dlls; } else { (my $p = ($ENV{$v} || '')) =~ s(\\)(/)g; my @path = grep length, split /;/, $p; s,([/\\]+)$,, for @path; if ($anyext) { push @found, <$_/*> for @path; } else { # include "No extension" push @found, grep /\.(?:exe|com|cmd|bat|btm|pl|sh|ksh)$/i || !m(\.[^/]*$), <$_/*> for @path; } } @found = grep /$rex/, @found; die "No matching files found\n" unless @found; @found = $found[0] unless $all; print "$_\n" for @found;