in reply to Re: Variables out of scope using END and Error.pm
in thread Variables out of scope using END and Error.pm

I'm not sure if that explenation is 100% correct...

If for example you change 'END' to sub abc (or anything, which is a named sub aswell) else and call it, then it does print 1.

Replies are listed 'Best First'.
Re^3: Variables out of scope using END and Error.pm
by dave_the_m (Monsignor) on Feb 18, 2005 at 02:18 UTC
    I'm not sure if that explenation is 100% correct...
    On the other hand, I am sure :-)

    The only difference between END and a normal sub in this case is that the END is called after the variable has normally gone out of scope. The following demonstrates the buggy behaviour for ordinary subs (on perl < 5.9.0) by artifically reducing the scope of the variable

    { my $x = 1; sub foo { # commenting this out causes the print to see an undef value $x; sub { print "x=$x\n" }->(); } } foo();

    Dave.