Hi

There is probably a module somewhere that does it.. but the following function
works as well .. may need to clean up the items returned from path as they may
have "\" on the end, butt still works.

Helen


sub which ( $ )
{
  my ( $file ) = @_ ;

  $path = $ENV{"PATH"} ;

  foreach $dir (split (/;/, $path))
  {
    return "$dir\\$file" if ( -e "$dir/$file" ) ;
  }

  return "not found" ;
}




print which ("cmd.exe") ;

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Behalf Of Dax
> T. Games
> Sent: 27 September 2003 22:10
> To: [EMAIL PROTECTED]
> Subject: 'which' functionality in Perl
>
>
> How would I determine if a file existed in a directory in the
> PATH environment variable on a Windows box with Perl.  If the
> file exists I want to return the full path to the file.
>
> The functionality I want is similar to 'which' on Unix/Linux.
>
> Thanks,
>
> Dax
>
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to