How does opendir work in Perl 6?
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:
H开发者_开发技巧ello, 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)
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.
opendir is just not yet implemented. Please file a bug report by sending a mail to rakudobug@perl.org.
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';
精彩评论