http://www.perlmonks.org?node_id=11131108


in reply to Check for another program availability

I'd avoid reimplementing how your shell uses $PATH. If this command is being run in a wrapper, it could be as simple as a commandline argument,
$ perl ./my/script.pl $(which myprogram)

If you don't know the name of the program at first, then,
my $full_program = `which $program`; chomp $full_program;
Note: which will not "find" a program in $PATH for a file where -x is not also true. In other words, which requires the "found" file to have executable permissions by the effective user. So, yeah; don't try to reimplement which.

Replies are listed 'Best First'.
Re^2: Check for another program availability
by hrcerq (Scribe) on Apr 11, 2021 at 22:49 UTC

    I see, but, would that be portable? I mean, the which program itself may not be available.

      > portable
      You didn't say it had to be "portable on Windows".

        It doesn't. But even on Unix I have no guarantee that which will be installed on the system.