Skip to content

Instantly share code, notes, and snippets.

@moritz
Created March 1, 2014 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/9292385 to your computer and use it in GitHub Desktop.
Save moritz/9292385 to your computer and use it in GitHub Desktop.
A simple closures example, with file walking
#!./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