Actually,

I would bet that the other instances of detecting the OS could be resolved
using the File::Spec module as well?

I have attached Jenda's Which.pm Version 0.3

John


John Pataki wrote:

> Jenda,
> I used the routine proposed by Jeremy in his reply and that also works very
> nicely.
> Perhaps this is the better choice? Version 0.4?
>
> Change 1 ->
> add
> require File::Spec;
>
> Change 2 ->
> replace the following subroutine
>
>  foreach $dir (@dirs) {
>   $dir = '.' unless $dir;
>   $dir =~ s{[/\\]$}{}g;
>   if ($^O =~ /MSWin32/i) {
>    foreach $extn (@extn) {
>     -e $dir.'\\'.$file.$extn and return $dir.'\\'.$file.$extn;
>    }
>   } else {
>    -x $dir.'/'.$file and return $dir.'/'.$file;
>   }
>  }
>
> with this subroutine
>
>   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 );
>      }
>   }
>
> John
>
> Jenda Krynicky wrote:
>
> > > Jenda,
> > >
> > > WOW.. ask and you shall receive. Thanks!
> > > Nice work. It is almost as if you just created that as if I wrote that
> > > email?
> >
> > No. I only dug it up in my old files.
> >
> > > I was looking at the module and I was wondering ... in the following
> > > routine ->
> > >
> > >   if ($^O =~ /MSWin32/i) {
> > >    foreach $extn (@extn) {
> > >     -e $dir.'/'.$file.$extn and return $dir.'/'.$file.$extn;
> > >    }
> > >   } else {
> > >    -x $dir.'/'.$file and return $dir.'/'.$file;
> > >   }
> > >  }
> > >
> > > ... you are checking the dir and file path using '/' for Windows...
> > > why? If Windows uses \ and not / then don't you want to display it
> > > back as the native format?
> >
> > You are right.
> >
> > > chop $dir if $dir =~ /\\$|\/$/;
> > > # Change 1 -> strip off ending slash if it exists
> >
> > Done ... though a little diferently.
> >
> > 0.3 was uploaded on my site.
> >
> > 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

Which.pm

Reply via email to