in reply to how to declare a package variable
Certainly read the tutorials linked by AnonyMonk above.
Then consider the following code:
In this code:c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; package P; ;; $P::A = 'something'; ;; package main; ;; my $A = 123; $::A = 456; ;; print 'package ', __PACKAGE__; print qq{\$A is $A}; print qq{\$::A is $::A}; print qq{\$main::A is $main::A}; print qq{\$P::A is $P::A}; print qq{\n}; ;; our $A; print 'package ', __PACKAGE__; print qq{\$A is $A}; print qq{\$::A is $::A}; print qq{\$main::A is $main::A}; print qq{\$P::A is $P::A}; " "our" variable $A masks earlier declaration in same scope at -e line 1 +. package main $A is 123 $::A is 456 $main::A is 456 $P::A is something package main $A is 456 $::A is 456 $main::A is 456 $P::A is something
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to declare a package variable
by scigeek (Initiate) on Apr 15, 2016 at 09:34 UTC | |
by BrowserUk (Patriarch) on Apr 15, 2016 at 09:50 UTC | |
by scigeek (Initiate) on Apr 15, 2016 at 10:10 UTC | |
by BrowserUk (Patriarch) on Apr 15, 2016 at 11:09 UTC | |
by AnomalousMonk (Archbishop) on Apr 15, 2016 at 12:05 UTC |