At 1:06 AM +0100 11/16/03, Michael Lemke wrote:
>While doing some porting I noticed this inconsistency between Unix
>and VMS with catdir.
>
>VMS> perl -e "use File::Spec::Functions; print catdir("""",'a','b');
>[.a.b]
>VMS> perl -e "use File::Spec::Functions; print catdir("" "",'a','b');
>a:[b]
>
>I'd expect to get an absolute path in both cases.  In fact, only the first
>should give a correct answer.  On Unix it behaves as I expect:
>
>unix> perl -e "use File::Spec::Functions; print catdir('','a','b');"'print "\n";'
>/a/b
>unix> perl -e "use File::Spec::Functions; print catdir(' ','a','b');"'print "\n";'
> /a/b

I'm not so sure that a zero-length string and a space should be
considered the same.  But I agree the second VMS example is a bit odd
in that a space is not considered a volume name but the next element
in the list is.  There may be a bug here, or it just may be undefined behavior.

>
>This is with perl 5.8.2 and the File::Spec that comes with it.
>
>This problem prevents me to do this:
>
>catdir( split('/','/some/absolute/path') );
>
>
>Or more to the point, how do you do this in a portable way:
>
>$r = '/root';
>$y = $r . '/subdir/subsubdir';
>$z = $r . '/subdir1';

The first thing to remember if you want to be portable is never to
look for a particular, platform-specific directory separator.  The
implication here would be to refrain from using split().  Have a look
at File::Spec->splitpath().  As Michael suggested, also look at
catpath() for putting the pieces back together.


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

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

Reply via email to