Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Static Variables in Perl

by benizi (Hermit)
on Mar 31, 2006 at 22:36 UTC ( [id://540560]=note: print w/replies, xml ) Need Help??


in reply to Static Variables in Perl

How's this?

$ head -n 1 *.pm ==> AA.pm <== package AA; use base qw/Exporter/; our @EXPORT=qw/$knob1/; our $knob1 += 'no'; 1 ==> BB.pm <== package BB; use AA; our @ISA=qw/AA/; our @EXPORT=qw/$knob1/; 1 ==> CC.pm <== package CC; use BB; our @ISA=qw/BB/; our @EXPORT=qw/$knob1/; 1 $ perl -MCC -MBB -lwe '$BB::knob1=42; print for $AA::knob1, $BB::knob1 +, $CC::knob1' 42 42 42

Note, however, that the following *doesn't* work. (use base doesn't call import)

$ head -n 1 *.pm ==> AA.pm <== package AA; use base qw/Exporter/; our @EXPORT=qw/$knob1/; our $knob1 += 'no'; 1 ==> BB.pm <== package BB; use base qw/AA/; our @EXPORT=qw/$knob1/; 1 ==> CC.pm <== package CC; use base qw/BB/; our @EXPORT=qw/$knob1/; 1 $ perl -MCC -MBB -lwe '$BB::knob1=42; print for $AA::knob1, $BB::knob1 +, $CC::knob1' no 42 Use of uninitialized value in print at -e line 1.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://540560]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-25 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found