in reply to Re: Problems with open
in thread Problems with open

I am using Perl 5.005_02 on a SunOS 5.6 machine. I thought of the -x pager but if the $pager does not contain the full path to whatever pager you are using (like less) then this is not going to work. I was hoping to find a cleaner way of doing this, but sounds like we are on the right track. I know we could always throw in a which, but like I said, I would like to find a cleaner way.

Thanks,

-sk

Replies are listed 'Best First'.
Re: Re: Re: Problems with open
by stajich (Chaplain) on Jul 24, 2002 at 16:50 UTC
    I guess if you wanted to check if $garbage is a valid exe before executing it you could do something like the following. I'm not sure what the behavior is on 5.002 with File::Spec - can probably replace that with split(/:/,$ENV{'PATH'});
    use File::Spec; sub valid_exe { my $exe = shift; for my $dir ( File::Spec->path() ) { my $f = File::Spec->catfile($dir,$exe); if( -e $f && -x $f ) { # it is a valid exe return 1; } } return 0; }
    Essentially what which will do for you, your call if it is cleaner.