use strict;
use warnings;
sub add{
my ($x, $y) = @_;
my $sum = $x + $y;
print "Sum within function: $sum\n";
return ($sum);
}
my $bb=\&add(10,1);
print $bb."\n";
my $cc=\&add;
print $cc."\n";
####
Sum within function: 11
SCALAR(0x3f7e24)
CODE(0xa3e58c)
####
use strict;
use warnings;
our $static_counter = 1;
sub add{
my ($x, $y) = @_;
my $sum = $x + $y;
print "Sum within function: $sum\n";
return ($sum);
}
sub counter {
my $cnt = $static_counter++;
print "Value of count in subroutine $cnt\n";
return($cnt);
}
sub mm{
my ($x, $y, $add_ref, $counter_ref) = @_;
my $cnt_in;
my $add_in;
my $mul = 1;
$mul = ($x * $y * &$add_ref(10,1) * &$counter_ref());
print "Multi : $mul\n";
$add_in = $add_ref->(20,5); ### Getting Error Here
### Not a Code Reference
$mul = ($x * $y * $add_in * $counter_ref->());
print "Multi : $mul\n";
return $mul;
}
sub aa {
my $z;
$z = mm(4,5, \&add, \&counter);
$z = mm(4,5, \&add, \&counter);
}
aa();
####
Sum within function: 11
Value of count in subroutine 1
Multi : 220
Sum within function: 25
Value of count in subroutine 2
Multi : 1000
Sum within function: 11
Value of count in subroutine 3
Multi : 660
Sum within function: 25
Value of count in subroutine 4
Multi : 2000