programming-examples/perl/Subroutine/Accessing variables in subroutines.pl
2019-11-15 12:59:38 +01:00

20 lines
435 B
Perl

# In your subroutines, you can access the value of any global variable.
# A global variable is a variable that is accessible across the entire Perl script.
# A subroutine can use data set up by other parts of your Perl scripts:
#!/usr/bin/perl -w
# Accessing global variables in subroutines.
$a = 1;
$b = 4;
$value = add();
print "$a plus $b is $value.\n";
sub add {
return ($a + $b);
}
# sub3.pl