I'm trying to list all files in a directory with this function:
sub list-directory($dir = '.') {
my @todo = $dir.IO.dir;
@todo = @todo.duckmap( -> $_ where $_.d { @todo.push($_.IO.dir); } );
@todo = @todo.duckmap( -> $_ where IO {.Str} );
return @todo;
}
The first duckmap is to list all subdirectories and the second one (this doesn't finish) is to convert the IO objects to Str.
Anyone knows why the second one isn't stopping?
As Hakon has said, it was a infinite loop. Here is the code fixed:
sub list-directory($dir = '.') {
my @todo = $dir.IO.dir;
@todo = @todo.duckmap( -> $_ where $_.d { @todo.push($_.IO.dir); $_; } );
grep { !.IO.d }, @todo.List.flat;
@todo.map({.Str});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With