Michael G Schwern <[EMAIL PROTECTED]> wrote:

> Why wouldn't appending no filename onto a directory result in the
directory
> being returned?  Unless append_filename() guarantees that it will always
> return a filepath ending in a filename?

Yes. And it guarantees to return a "", when you do something that
it treats as wrong in it's point of view.

> > append_filename("", "b") will produce "b"
>
> Now wait a second.  append_filename("a", "") produces nothing but
> append_filename("", "b") produces a filename?  Isn't that a little
> inconsistent?

No, it isn't. In the first case it returns "" being standing for to
indicate an error situation. In the second case,

append_filename("", "b") will give you ":b" on Mac.

It does sense, when you want to get a relative filepath which is
a route to the file b in the current directory.

> Famous last words: "Our data is perfect, we don't need to check our
inputs."

Yes. Our data is perfect and we don't need to check our inputs if we
play by rules. And the rules are:

Always use concat_dirnames to concatenate directory names
Always use append_filename to append a file name to a path
Always keep in mind that this tool gives you a proper result
when you give it proper input, which is simple directory
names, simple file names, and paths produced by this tool only.

If you observe the rules, you won't get into a mess.

> Ok, but what happens when I pass filepaths with volumes attached to
> concat_dirnames?

You get what you do, nonsense. Even File::Spec, a tool of a lot more
higher level, doesn't protect you from such things.

D:\>perl -MFile::Spec::Functions -e "print catdir('C:\hh','C:\dd'), qq(\n)"
C:\hh\C:\dd

>What if the volumes don't match?

Don't match against what? concat_dirnames doesn't do matching arguments
against anything but PARROT_FS_DIRNAME_START and PARROT_FS_DIRNAME_END,
which, for example, are '[' and ']' on VMS.

> What if I'm adding a path with a volume to one without?

Still. You get what you do. On Mac:

concat_dirnames('my disk:a', ':b') = ':my disk:a:b'

File::Spec has an individual function for such purposes, catpath().
We can't process more than two in-arguments in PASM, so we would take
advantage of prepend_volume and things of such sort.


Reply via email to