in reply to Why no stay shared warning?
Look carefully at your code... What order will each statement be executed in? The calls to up() and get() are actually executed before the initialization of $foo to 1.
In order to get the result you want, you need to make sure that the $foo = 1 line is executed before any of the subroutine calls. One way to do this is:
use strict; use diagnostics; up(); up(); print get(); { my $foo; BEGIN { $foo = 1; } sub up { $foo++ } sub get { $foo } }
|
|---|