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, October 15, 2010

Perl typeglobs and symbol table

*a represents the symbol table entry for a, ie a hidden binary structure that, when it's prefixed with $, @ etc, or used in filehandle context etc, the appropriate element is selected and used.

$::{'a'} does basically the same thing.

You can do a dereference on $::{'a'}, or indeed in this situation

$a = 9; *b = *a; print ${*b};

though I don't know whether this works because typeglobs and references are really interchangeable or whether some kind of soft dereferencing is happening automatically to make this work.

(The Perl 4 programming book says that %_main holds the symbol table for package main, but this doesn't seem to work now. Presumably $:: replaced it.)

Advanced Perl Programming says that assigning a reference to a typeglob

$a = 9; *b = \$a;

will change only the appropriate part of *b to a reference to $a. Ie after the above example, $b will be 9 but @b, %b etc will be unaffected.

The suggestion in APP is the sub-elements inside a typeglob are references, which is why the above would work, but it doesn't say that explicitly.

Followers

Blog Archive