I've been always told NOT to do what you're advising here,
if you're forking off many children, and put the same data into every one of those, you get No#Children*DataStructureSize memory consumption, if you initalise everything in master thread, then the children will have their own copy-on-write copy of the datastructure, and you get 1*DataStructureSize memory consumption.
in reply to threads: spawn early to avoid the crush.
Although it looks like your advice, when it comes to perl and not general computing, is right:
paranoid% perl -w junk1.pl
Taken 1.603796 seconds%
paranoid% perl -w junk2.pl
Taken 4.308179 seconds%
I'm still avoiding threads with perl, there's no good reason for lib authors to make their libs thread-safe, thus your perl apps will never be thread-safe, and, there is basically nothing that threading has to offer (well, headaches and longer development times, but if we wanted that, we would be programming java)
(But we do get a lot of people who read a book about GUIs, and they can't seem to live without threads these days)
A computer is a state machine. Threads are for people who can't program state machines. -- Alan Cox