Question: Run the following program in Perl: You may be surprised by the output. Perl 5 allows named subroutines to nest, but does not create closures
Run the following program in Perl:
![sub foo { my $lex = $_[o]; sub bar { print](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1606/3/7/0/8435fbf461ba95e41606370843396.jpg)
You may be surprised by the output. Perl 5 allows named subroutines to nest, but does not create closures for them properly. Rewrite the code above to create a reference to an anonymous local subroutine and verify that it does create closures correctly. Add the line use diagnostics; to the beginning of the original version and run it again. Based on the explanation this will give you, speculate as to how nested named subroutines are implemented in Perl 5.
sub foo { my $lex = $_[o]; sub bar { print "$lex "; bar (); foo (2); foo(3);
Step by Step Solution
3.52 Rating (172 Votes )
There are 3 Steps involved in it
The rewritten code should look like this use diagn ostics sub foo ... View full answer
Get step-by-step solutions from verified subject matter experts
