opendir 在 Perl 6 中如何工作?

发布于 2024-08-23 02:20:26 字数 878 浏览 5 评论 0原文

有人可以告诉我,为什么“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 ((未知文件):-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) 调用

Can someone tell me, why the "opendir" doesn't work?

#!/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: $!";

Output:

Hello, World!
Line 2.
Last line.

Could not find non-existent sub &opendir
current instr.: '_block14' pc 29 (EVAL_1:0)
called from Sub '!UNIT_START' pc 1163 (src/glue/run.pir:20)
called from Sub 'perl6;PCT;HLLCompiler;eval' pc -1 ((unknown file):-1)
called from Sub 'perl6;PCT;HLLCompiler;evalfiles' pc 1303 (compilers/pct/src/PCT/HLLCompiler.pir:707)
called from Sub 'perl6;PCT;HLLCompiler;command_line' pc 1489 (compilers/pct/src/PCT/HLLCompiler.pir:794)
called from Sub 'perl6;Perl6;Compiler;main' pc -1 ((unknown file):-1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一笑百媚生 2024-08-30 02:20:26

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 等。

Perl6 is ready now. So we can give a correct answer to this very old question.

There is no more opendir in Perl6. But thanks to many people who work on Perl 6, open a dir is now very simple.

As perl - dir doc says:

Opening a directory requires just to type:

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

And with a filter:

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

So you can forget opendir, readdir, grep and other.

金兰素衣 2024-08-30 02:20:26

opendir 还没有实现。请发送邮件至 [email protected] 来提交错误报告。

opendir is just not yet implemented. Please file a bug report by sending a mail to [email protected].

梦行七里 2024-08-30 02:20:26

我没有 Perl 6,但看起来您错误地调用了 opendir。这个 Perl 片段对我有用:

my $dh;
opendir $dh, '/home/ar' or die 'Could not open directory';

I don't have Perl 6, but it looks like you are calling opendir incorrectly. This perl snippet works for me:

my $dh;
opendir $dh, '/home/ar' or die 'Could not open directory';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文