http://www.perlmonks.org?node_id=36807

nop has asked for the wisdom of the Perl Monks concerning the following question:

Snippet from perlref:
sub newprint { my $x = shift; return sub { my $y = shift; print "$x, $y!\n"; }; } $h = newprint("Howdy"); $g = newprint("Greetings"); # Time passes... &$h("world"); &$g("earthlings"); This prints Howdy, world! Greetings, earthlings! Note particularly that $x continues to refer to the value passed into +newprint() despite ``my $x'' having gone out of scope by the time the + anonymous subroutine runs. That's what a closure is all about.
Can someone explain the last cryptic paragraph? It seems to me that "my $x" has gone out of scope by the time the anon sub runs... is the value still around because there remains a ref to it? If so, what is doing the ref... the anon sub itself? Clarification welcome... thanks.