Even better, use the File::Spec::* modules to get portable file
handling routines:

use File::Spec;

foreach $dir (@dirs) {
   $dir = File::Spec->curdir unless $dir;
   $dir = File::Spec->canonpath( $dir );
   if ($^O =~ /MSWin32/i) {
      foreach $extn (@extn) {
         -e File::Spec->catfile( $dir, "$file$extn" ) and
            return File::Spec->catfile( $dir, "$file$extn" );
      }
   } elsif( -x File::Spec->catfile( $dir, $file ) ) {
      return File::Spec->catfile( $dir, $file );
   }
}


-- 

Jeremy Wadsack
Wadsack-Allen Digital Group


John Pataki ([EMAIL PROTECTED]):

> Jenda,

> What do think about these changes I propose to your module?
> I didn't realize it was so easy to write perl module?
> Man, I love Perl.

>  foreach $dir (@dirs) {
>   $dir = '.' unless $dir;
>   chop $dir if $dir =~ /\\$|\/$/;  # Change 1 -> strip off ending slash if it
> exists
>   if ($^O =~ /MSWin32/i) {
>    foreach $extn (@extn) {
>     -e $dir.'\\'.$file.$extn and return $dir.'\\'.$file.$extn; # Change 2 ->
> use \ for MSWin32 directories
>    }
>   } else {
>    -x $dir.'/'.$file and return $dir.'/'.$file;
>   }
>  }

> John




> John Pataki wrote:

>> ... meant to include this in previous email
>>
>> Example:
>>
>> D:\>test_file.pl
>> Path to perl is : C:\Perl\bin\/perl.EXE
>>
>> D:\>test_file.pl
>> Path to notepad is : C:\WINNT\system32/notepad.EXE
>>
>> John
>>
>> Jenda Krynicky wrote:
>>
>> > > > I want to determine if a particular exectuable file is
>> > > > available/exists within the path. Is there a switch or function
>> > > > available to with/instead of the -x test? I have an example to
>> > > > illustrate the results of what I want to do with a simpler approach.
>> >
>> > If you want it nicely packaged you may download File::Which from
>> > http://Jenda.Krynicky.cz/perl/Which.pm
>> >
>> >         use File::Which;
>> >         print "Path to notepad is : ",which('notepad'),"\n";
>> >
>> > it should work OK under Win32 and Unix (not tested under *nix
>> > though). Under Windows it checks the system variable PATHEXT
>> > for what is the local list of "executable" extensions.
>> >
>> > Jenda
>> >
>> > == [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==
>> > : What do people think?
>> > What, do people think?  :-)
>> >              -- Larry Wall in <[EMAIL PROTECTED]>
>> > _______________________________________________
>> > ActivePerl mailing list
>> > [EMAIL PROTECTED]
>> > http://listserv.ActiveState.com/mailman/listinfo/activeperl
>>
>> _______________________________________________
>> ActivePerl mailing list
>> [EMAIL PROTECTED]
>> http://listserv.ActiveState.com/mailman/listinfo/activeperl

> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/activeperl

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to