I want to have a sub inside another sub,
sub a {
sub b {
}
}
I want to create a new instance of sub b
for every call to sub a
. Is there a way to do this in Perl?
When I run the code above and print the address of sub b
in sub a
I always get the same address for sub b
like
sub a {
print \&b;
sub b{
}
}
This link on Perl Monks says that we can do this, but I always see the same address for sub b
.
Is there a way to create a new instance of sub b
for every call to sub a
?
sub a {
sub b{
}
}
is basically the same as:
sub a {
}
sub b{
}
because named subroutines live in the symbol table hence they are global. you will need to return a reference to a subroutine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With