Skip to content

Instantly share code, notes, and snippets.

@m-doughty
Created September 22, 2020 13:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-doughty/1a22ce833f707303d84c4c630044c425 to your computer and use it in GitHub Desktop.
Save m-doughty/1a22ce833f707303d84c4c630044c425 to your computer and use it in GitHub Desktop.
Pure & impure functions
# This is an impure function, calling double will return 2 the first time, then 4, then 8...
my $input = 1;
sub double {
$input = $input * 2;
return $input;
}
# This is a pure function, calling triple(1) will always return 3.
sub triple {
my $n = shift;
return $n * 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment