1

有人可以告诉我,为什么“opendir”不起作用?

#!/usr/bin/env perl6
use v6;

my $file = 'Dokumente/test_file';

if ( my $fh = open $file, :r ) {
    for $fh.lines -> $line {
    say $line;
    }
} else {
    say "Could not open '$file'";
}


my $dir = 'Dokumente';

my $dh = opendir $dir err die "Could not open $dir: $!";

输出:

你好世界!
第 2
行。最后一行。

找不到不存在的子 &opendir
当前指令:'_block14' pc 29 (EVAL_1:0)
从 Sub '!UNIT_START' pc 1163 (src/glue/run.pir:20)
调用从 Sub 'perl6;PCT; HLLCompiler;eval' pc -1 ((unknown file):-1)
从 Sub 'perl6;PCT;HLLCompiler;evalfiles' pc 1303 (compilers/pct/src/PCT/HLLCompiler.pir:707)
调用从 Sub 'perl6 ;PCT;HLLCompiler;command_line' pc 1489 (compilers/pct/src/PCT/HLLCompiler.pir:794)
从 Sub 'perl6;Perl6;Compiler;main' pc -1 ((未知文件):-1) 调用

4

3 回答 3

3

Perl6 现在准备好了。所以我们可以对这个非常古老的问题给出正确的答案。

Perl6 中不再有 opendir。但是感谢许多使用 Perl 6 的人,现在打开一个目录非常简单。

正如perl - dir doc所说:

打开一个目录只需要输入:

for dir() -> $file {
    say $file;
}

并带有过滤器:

for dir('/path/to/dir', test => /\.jpg$/ ) -> $file {
    say $file;
}

所以你可以忘记 opendir、readdir、grep 等。

于 2018-09-25T12:31:13.063 回答
1

opendir 还没有实现。请发送邮件至 rakudobug@perl.org 提交错误报告。

于 2010-02-28T17:48:27.877 回答
-2

我没有 Perl 6,但看起来你调用 opendir 不正确。这个 perl 片段对我有用:

my $dh;
opendir $dh, '/home/ar' or die 'Could not open directory';
于 2010-02-26T16:52:14.570 回答