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

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

I am hacking together an application under Win98 with ActiveState perl 5.6.1, that forks a child process that does most of the work. To earlier avoid confusion (futher described in Win98 Socket Woes) over parent and child copies of data, I got the bright idea to put the child in its own package, so only the child could see the application data.

OTOH, the whole thing isn't really big enough to warrant chopping into modules, so I kept it all in a single file, like so:

use strict; use warnings; &Hello::printit; package Hello; sub printit; our($b) = "Hello, world!\n"; sub printit { print $b; }

When I run the above, I get warned that $b is undefined in the print call.

If I split the above into two files, and "require Hello;" in the main, the message prints OK.

The difference must lie in how and when "our($b)=..." gets executed, and where $b gets defined. But I would have expected $b to be defined in package Hello, either way.

Any explanations would be welcome!

(Note: there's no fork in the above example; fork isn't the problem, it's just the motivation for splitting things up)

Thanks! -- Dinosaur