As you can see, is the file in one of the directories specified in $ENV{PATH}
without looking at $ENV{PATH}
? & Hellip; This is a rhetorical question.
Here is a short script I wrote some time ago. You must be able to adapt it for your needs:
#!/usr/bin/perl use strict; use warnings; use File::Basename; use File::Spec::Functions qw( catfile path ); my $myname = fileparse $0; die "Usage: $myname program_name\n" unless @ARGV; my @path = path; my @pathext = ( q{} ); if ( $^O eq 'MSWin32' ) { push @pathext, map { lc } split /;/, $ENV{PATHEXT}; } PROGRAM: for my $progname ( @ARGV ) { unless ( $progname eq fileparse $progname ) { warn "Not processed: $progname\n\tArgument is not a plain file name\n"; next PROGRAM; } my @results; for my $dir ( @path ) { for my $ext ( @pathext ) { my $f = catfile $dir, "$progname$ext"; push @results, $f if -x $f; } } print "$progname:\n"; print "\t$_\n" for @results; }
source share