You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
521 B
Perl

# Perl allows you to create local variables inside subroutines.
# The local variables can have the same names as any global variables.
# The local won't overwrite the global variables.
# To make a variable local, use the my command
#!/usr/bin/perl -w
$a = 1;
$b = 4;
# sum is global.
$sum = 10;
$value = add();
print "$a plus $b is $value.\n";
print "Global sum remains $sum.\n";
sub add {
# This sum is local.
my($sum) = $a + $b;
print "Local sum=$sum.\n";
return $sum;
}