in reply to Closures clarification
You were missing the "use" statement, missing a "(" in the find function, and the "{" in the sub definition was misplaced.use File::Find; my $total_size = 0; find(sub {$total_size += -s if -f}, '.'); print $total_size, "\n";
So, here the subroutine is a closure because it refers to the lexical variable $count.use File::Find; my $callback; { my $count = 0; $callback = sub { print ++$count, ":$File::Find::name\n" }; } find($callback, '.');
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Closures clarification
by lodin (Hermit) on Dec 04, 2007 at 14:52 UTC | |
by memnoch (Scribe) on Dec 04, 2007 at 15:52 UTC | |
Re^2: Closures clarification
by fenLisesi (Priest) on Dec 04, 2007 at 14:11 UTC | |
by memnoch (Scribe) on Dec 04, 2007 at 16:35 UTC |