[Israel.pm] How to "which" in Perl

Shlomi Fish shlomif at iglu.org.il
Sun Jan 25 06:46:56 PST 2004


On Sunday 25 January 2004 16:24, David Baird wrote:
> Mongers,
>
> Does anyone know how to do "which" in pure Perl? I would like to find
> the execution path of a command through a "perl -e" operation for a GNU
> Make $(shell ) macro. I am running on Windows XP with ActivePerl 5.6.1.
> I don't have a which command available, and do not want to require
> Cygwin.
>

<<<
#!/usr/bin/perl -w

use strict;

use Env::Path;

sub which
{
    my $program = shift;
    my $path = Env::Path->PATH; 
    foreach ($path->List()) 
    { 
        my $full_name = "$_/$program";
        if (-x $full_name) 
        { 
             return $full_name;
        }
    }
    return undef;
}

my $program = shift(@ARGV);
print which($program), "\n";
>>>

Regards,

	Shlomi Fish

> Thanks,
> David
>
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://www.perl.org.il/mailman/listinfo/perl
>
> YAPC::Israel::2004
> http://www.perl.org.il/YAPC/2004/

-- 

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage: http://t2.technion.ac.il/~shlomif/

I don't believe in fairies. Oops! A fairy died.
I don't believe in fairies. Oops! Another fairy died.




More information about the Perl mailing list