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 )

Friday, January 31, 2014

Perl use constant

The new constants declared by 'use constant' are very useful, but if like me you test your new packages by putting a stub at the top of the .pm file, you'll run into this gotcha:
$m = new Package;
$m->doit(Package::RED);

{
package Package;

use constant RED => 0xFF0000;

...
}
The call to doit will supply the string "Package::RED" not 0xFF0000 - because constant declaration and substitution both happen at compile time, and the doit call is compiled before the use constant because the former is reached first.

The solution is to put the stub after the package.

Thursday, January 30, 2014

Perl => quoting

=> quotes the thing to the left of it - but it does not preserve leading zeroes if that thing is a number. %h = ( 00 => "null" ) will result in '0' being the hash key, not '00'.

Followers

Blog Archive