Last active
September 30, 2015 04:38
-
-
Save jreisinger/1723314 to your computer and use it in GitHub Desktop.
Global variable vs. function with argumet
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
# | |
# 1. global variable | |
# | |
my $num = 2; | |
exp(); | |
sub exp { | |
return $num * $num; | |
} | |
# | |
# 2. function with argument | |
# | |
my $num = 2; | |
exp($num); | |
sub exp { | |
my $num = shift; # local to exp | |
return $num * $num; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment