perl - How can I import global variables from a base module? -


I created a module Foo :: prototype with the global variable $ A and $ B. I want the package Foo :: Bar which uses the Foo :: prototype as a base to import global variables $ A and $ B I do not understand how to do this.

I understand that using global variables is not a good practice in general, but in this situation I want to use them.

The code looks like this:

  Package Foo: prototype; My ($ A, $ B); Our @EXPORT = qw ($ A $ B); Sub New {[...] $ A = 1; $ B = 2; } 1; Package Fu: Bar; Use Base Fu: Prototype QW ($ A $ B); Sub-trial {print $ A, "\ n"; Print $ B, "\ n"; } 1; # Test.pl Foo: Bar- & gt; new (); Foo: Bar-> testing ();  

Edit:

I want to write Compact Foo :: Prototype sub class as possible for other people. Instead of writing $ self-> {A} -> foo (), I want to let people write $ a-> foo ().

T.pm:

Package T; Strict use; Use warnings; Use base 'exporter'; Our ($ A, $ B); Our @EXPORT = qw ($ A $ B); Sub new {$ A = 1; $ B = 2; } "EOF T.pm"

Umpm:

  Package U; Strict use; Use warnings; Use Base 'T'; Use t; Sub-trial {My $ self = shift; Print $ "$ _ \ n" $ A, $ B; } "EOF U.pm"  

t.pl:

  #! / Usr / perl / bin strict; Use warnings; Use U; U & gt; New; U & gt; testing; C: \ Temp & gt; T.pl 1 2  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -