At 9:56 PM -0600 2/8/06, Ken Williams wrote:
>Hi Steven,
>
>On VMS is 'USER:[SLEMBARK.FINDBIN-LIBS-1_20]' an absolute path, i.e. is the 
>SLEMBARK directory understood to be at the root of the USER volume? 

Yes.  You would not see the volume name if it weren't an absolute path.

>If so, probably splitpath() is actually returning the wrong result.  On other 
>platforms it returns an initial empty string to indicate an absolute path 
>(it's kind of an historical accident, but now that's just its semantics):

The documentation states that the first item returned is the volume,
and "On systems with no concept of volume, returns '' for volume."  I
would take this to mean that the volume would be an empty string on,
for example, unix, regardless of whether the path is relative or
absolute.  On VMS, it returns the empty string for the volume when
there is no volume in the input parameter, i.e., the path is relative.

Perhaps I'm misunderstanding something, but I can't see how an empty
volume name could ever indicate an absolute path.

>
>
>% perl -MFile::Spec::Functions=:ALL -de1
>...
>  DB<1> x $bin = '/foo/bar/baz';
>0  '/foo/bar/baz'
>  DB<2> x ( $vol, $dir ) = splitpath $bin;
>0  ''
>1  '/foo/bar/'
>  DB<3> x @subdirz = splitdir $dir;
>0  ''
>1  'foo'
>2  'bar'
>3  ''
>  DB<4> x $libdir = catdir @subdirz, 'lib';
>0  '/foo/bar/lib'
>
>That empty string is the only clue catdir() gets that it should be forming an 
>absolute path instead of a relative one.

Perhaps on VMS, splitdir should do the same thing splitpath does and
return the volume as the first element.  I'm concerned about what
that might break, though.

>
>Then we'll need to make sure catdir('', 'SLEMBARK', 'FINDBIN-LIBS-1_20', 
>'lib') returns the right result too, '[SLEMBARK.FINDBIN-LIBS-1_20.lib]'.
>
> -Ken
>
>
>On Feb 8, 2006, at 6:00 PM, Steven Lembark wrote:
>
>>
>>Notice the 6th statement adds a leading '.' to the directory.
>>
>>  DB<1> use File::Spec::Functions qw( splitpath splitdir catpath catdir );
>>  DB<2>  use FindBin;
>>
>>  DB<3> x ( $bin ) = $FindBin::Bin =~ m{(.+)};
>>0  'USER:[SLEMBARK.FINDBIN-LIBS-1_20]'
>>
>>  DB<4> x ( $vol, $dir ) = splitpath $bin;
>>0  'USER:'
>>1  '[SLEMBARK.FINDBIN-LIBS-1_20]'
>>
>>  DB<5> x @subdirz = splitdir $dir;
>>0  'SLEMBARK'
>>1  'FINDBIN-LIBS-1_20'
>>
>>  DB<6>  x $libdir = catdir @subdirz, 'lib';
>>0  '[.SLEMBARK.FINDBIN-LIBS-1_20.lib]'
>>
>>  DB<7> x $path = catpath $vol, catdir @subdirz, 'lib';
>>0  'USER:[.SLEMBARK.FINDBIN-LIBS-1_20.lib]'

Passing a list of directory names to catdir is always going to return
a relative path.  The only way I know of to make clear you want an
absolute path is to include the volume name:

  DB<13> x ($vol,$dir) = splitpath('dev:[foo.bar.baz]')                         
                                                   
0  'dev:'
1  '[foo.bar.baz]'
  DB<14> x @dirs = splitdir $dir
0  'foo'
1  'bar'
2  'baz'
  DB<15> x $rejoin = catdir($vol, @dirs)
0  'dev:[foo.bar.baz]'

-- 
________________________________________
Craig A. Berry
mailto:[EMAIL PROTECTED]

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Reply via email to