在 IO::Path 中§
请参阅方法 chdir的上下文中的主要文档 in context
multi method chdir(IO::Path: IO , |c)multi method chdir(IO::Path: Str() , : = True, :, :, :)
与名称相反,.chdir 方法不会更改任何目录,而只是将给定的 $path 与调用者连接,并返回结果 IO::Path。可以通过提供 :d、:r、:w 或 :x Bool 命名参数来执行可选文件测试;当设置为 True 时,它们将分别执行 .d、.r、.w 和 .x 测试。默认情况下,只有 :d 设置为 True。
在独立例程中§
请参阅子例程 chdir的上下文中的主要文档 in context
sub chdir(IO() , : = True, :, :, : --> IO::Path)
将 $*CWD 变量的值更改为提供的 $path,并可以选择确保新路径通过多个文件测试。注意:此例程不会更改进程的当前目录(请参阅 &*chdir)。
如果成功,则返回表示新 $*CWD 的 IO::Path。如果失败,则返回 Failure 且不更改 $*CWD。$path 可以是任何具有 IO 方法的对象,该方法返回 IO::Path 对象。可用的文件测试有
默认情况下,只执行 :d 测试。
chdir '/tmp'; # change $*CWD to '/tmp' and check its .d is Truechdir :r, :w, '/tmp'; # … check its .r and .w are Truechdir '/not-there'; # returns Failure
请注意,以下结构是一个错误
# WRONG! DO NOT DO THIS!my = chdir '/tmp/';
请改用 indir。