Skip to content

Instantly share code, notes, and snippets.

@hpcx82
Created November 30, 2011 02:05
Show Gist options
  • Save hpcx82/1407652 to your computer and use it in GitHub Desktop.
Save hpcx82/1407652 to your computer and use it in GitHub Desktop.
sub make_adder
{
  my $addpiece = shift;
  return sub { shift + $addpiece };
}
$f1 = make_adder(20);
&f1(1); # = 21;
&f1(2); # = 22;
@hpcx82
Copy link
Author

hpcx82 commented Jul 5, 2012

closure - use a local variable in another function, then you can use that function elsewhere, even it is not in the context of that local variable. (the local variable is either cloned, or ref-counted)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment