The suggested File::Which is probably *the* solution you want.
The suggested File::Spec is probably (very) good to get used to when writing code that should work on all types of OS's.
I want to add that returning the actual path of the tool/program/script/file is a lot more useful than returning 1.
I also want to say that your approach is less than perfect as you do not skip empty $PATH elements and elements that do not exist or are not a directory. This matters a lot if you are dealing with environments where the environment cannot be trusted. I'd suggest (ignoring both mentioned modules):
use List::Util qw( first ); sub available { my $prog = shift; first { -x "$_/$prog } grep { m/\S/ && -d } split m/:+/ => $ENV{PA +TH}; }
In reply to Re: Check for another program availability
by Tux
in thread Check for another program availability
by hrcerq
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |