Skip to content

Commit fd7a41b

Browse files
authored
[io grant] Improve code example
- remove Perl 5-ist parentheses - avoid repetition of a variable - fix incorrect Range (prose says "first three files") - gather IO::Paths, not strings - Don't use regex when we don't need it - No need to test .f
1 parent 9c2b726 commit fd7a41b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

doc/Type/IO/Path.pod6

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,15 @@ An example program that lists all files and directories recursively:
227227
A lazy way to find the first three files ending in ".p6" recursively starting from the current directory:
228228
229229
=for code :skip-test
230-
my @stack = '.';
231-
my $perl-files := gather while ( @stack ) {
232-
my $current = @stack.pop;
233-
take $current if ($current.IO.f && $current.IO.extension ~~ rx:i/p6$/);
234-
@stack.append(dir($current)>>.path) if $current.IO.d;
230+
my @stack = '.'.IO;
231+
my $perl-files = gather while @stack {
232+
with @stack.pop {
233+
when :d { @stack.append: .dir }
234+
.take when .extension.lc.ends-with: 'p6'
235+
}
235236
}
237+
.put for $perl-files[^3];
236238
=for code :skip-test
237-
say $perl-files[1..3];
238239
239240
=head2 method e
240241

0 commit comments

Comments
 (0)