Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, February 19, 2013

When are Perl globals initialised?

Code in the main part of a package file (outside any subs) runs during the compilation phase, ie when the "use" statement that loads the package is read by the compiler.

If you set globals (such as package 'locals') in such code, they will not still be set during execution - I'm guessing because globals are initialised to undefined when execution proper begins?

But then if I use a BEGIN block to set globals, they are still set when execution begins, even though BEGIN blocks are supposed to run during compilation too.

The import sub is also a suitable place to use as a workaround (presumably because it runs after BEGIN).

So I have a workaround for this, but I don't know why it works and the other way doesn't.

Followers

Blog Archive