in reply to 001-inpath verify if command is in PATH
in thread Wicked Cool Shell Scripts implemented in Perl
ditto on calin's comments ... esepecially that this function should just return a boolean, in which case it becomes one line:use File::Find::Rule; sub in_path { my ($cmd, $path) = @_; my @files = File::Find::Rule->file()->name($cmd)->maxdepth(1)->in( s +plit /:/, $path ) or return 'not found'; return grep(-x $_,@files) ? 'exe' : 'plain'; }
return File::Find::Rule->file()->executable->name($cmd)->maxdepth(1)-> +in( split /:/, $path ) ? 1 : undef;
|
|---|