in reply to Static Variables in Perl

Howdy!

...or, you could do something like the following:

package A; use vars qw/$knob1/; package B; @ISA=('A'); *knob1 = *A::knob1; package main; $A::knob1 = 'a knob1'; $B::knob1 = 'b knob1'; print $A::knob1, "\n"; print \$A::knob1, "\n"; print \$B::knob1, "\n";
which printed:
b knob1 SCALAR(0x10062530) SCALAR(0x10065230)
showing that the two variables are each a name for the same location.

yours,
Michael

Replies are listed 'Best First'.
Re: Static Variables in Perl
by benizi (Hermit) on Apr 01, 2006 at 07:00 UTC

    Did a double-take there... 'SCALAR(0x10062530)' ne 'SCALAR(0x10065230)'. But I assume that's a typo, since it works for me:

    b knob1 SCALAR(0x8145c50) SCALAR(0x8145c50)