On 2009-Aug-18, at 4:59 am, Carlin Bingham wrote:
2009/8/18 Timothy S. Nelson <wayl...@wayland.id.au>:
It's not in the revised spec, but I think that, even though we've revived chdir, we should still have it so that changing $*CWD will do a chdir under the hood.

While in the spirit of TIMTOWTDI, having a "magic" variable that behaves differently from other variables when it's being set would be rather odd.

But really, it isn't different.... After all, a "current path" IS just a string; it's a string that shells helpfully insert for you at certain points to save you some typing. The automatic insertion may be "magical", but the string itself is quite ordinary.


The metaphor of being "in" a directory is quite fascinating, really. Directories are not something you can be "in" -- they're lists that hang on the walls of office buildings, or get printed on the pages of a phone book. They're pointers, dir-ections to where you can find something -- an office, a telephone, or a file on a disk. Literally *on* the disk, not "in" it (disk platters are flat!). But this image of working "in" a directory seems to come quite easily and naturally.


It wouldn't seem magical if we always wrote like this:
    ls $PWD/foo/bar
    PWD = $PWD/foo
    ls $PWD/bar

That would still save a lot of typing, but not having to type the $PWD saves even more. But perhaps the apparent magic is that $*CWD = "/foo" sets the CWD to "/foo", but setting it to "foo" does not set the CWD to "foo", but rather to "$OLDCWD/foo". But that's not $*CWD's doing, that's our path-quoting.

    ~ p[/foo/bar] eq "/foo/bar"        # path literal cast to Str
    ~ p[foo/bar] eq "$CWD/foo/bar"

Not so strange to anyone familiar with the idea of relative paths, and no more magical than... say, the fact that a literal series of digits gets parsed as though it had an implicit "0d" in front of it. (Of course, I suspect that $*CWD should be able to be set to a plain Str, but the Str will be cast to an IO::Path because that's what $*CWD.STORE() will take in its signature.)


-David

Reply via email to