Re: File::Spec catfile etc.
[email protected] (Bart Lateur)
| Newsgroups | perl.perl5.porters,perl.macperl.porters,perl.vmsperl |
|---|---|
| Organization | MediaMind |
| Message-ID | <[email protected]> |
On Fri, 14 Sep 2001 10:21:19 -0400, Barrie Slaymaker wrote:
>On Thu, Sep 13, 2001 at 08:57:49PM -0400, Chris Nandor wrote:
>> 2. if the first argument is something denoting a root-level item ('/',
>> 'HD:', 'C:')
>
>When on that platform. This is so non-portable that I think we should
>emit warnings, so that code written on Win32, say, that calls
>
> $path = "C:\foo" ;
> $fullpath = File::Spec->catfile( $path, "bar" ) ;
>
>emits a warning about non-portable usage. However, I'd prefer that
>
> $fullpath = File::Spec::Win32->catfile( $path, "bar" ) ;
>
>not warn, though it's not a big deal to me.
Horrors. Here you're tossing away every chance of writing portable code.
Suppose you get your path like this:
use Cwd;
$fullpath = File::Spec->catfile(cwd, "bar" ) ;
then you'll get a warning, just because your root dir looks like
"c:/foo"?
And if you have to specify:
$fullpath = File::Spec::Win32->catfile(cwd, "bar" ) ;
then your code won't run properly on any other platform, will it?
No. Do not go that way. It's the author's responsibility to make sure he
doesn't unnecessarily hardcodes device dependent paths, if he wants his
code to be "portable". After all, chances are that if he writes
$fullpath = File::Spec::Win32->catfile("c:/foo/baz", "bar" ) ;
that the code will run on his own computer, but not on most other Win32
machines, simply because that directory doesn't even exist. In that
case, he'll probably skip the whole thing and simply write
$fullpath = "c:/foo/baz/bar";
p.s. WRT to what C.Nandor wrote: how would you even recognize a volume
name on a Mac? After all, it looks just like any other filename.
--
Bart.