Created
March 1, 2014 16:28
-
-
Save moritz/9292385 to your computer and use it in GitHub Desktop.
A simple closures example, with file walking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!./perl6-m | |
use v6; | |
sub MAIN($path = '.') { | |
my $counter = 0; | |
my $callback = sub ($file) { | |
$counter++; | |
say $counter, "\t", $file.Str; | |
}; | |
walk $path, $callback; | |
} | |
sub walk($dir, &callback) { | |
for dir($dir) -> $path { | |
if $path.d { | |
walk $path, &callback; | |
} | |
else { | |
callback($path); | |
} | |
} | |
} | |
# vim: ft=perl6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment