in reply to Re^16: the "our" declaration ?!! (special vars)
in thread the "our" declaration ?!!
first example:
OK, you want extend a singular declaration for a package to multiple files. That's handy when you want to split a big package into multiple files, but you can achieve this with "require" and "do".
#--- subfile my $file="our_reg.pm"; print "$file: $x";
#--- basefile use strict; my $file="our_base.pl"; $\="\n"; package one; our $x=__PACKAGE__; print "$file $x"; require our_req; package two; our $x=__PACKAGE__; print "$file $x"; do "our_req.pm";
for most other cases I can think of, it's IMHO better to use getter and setters for packvars, if you don't want to repeat the "our"-declaration.#--- OUTPUT /usr/bin/perl -w /home/lanx/perl/pm/declare/our_base.pl our_base.pl one our_reg.pm: one our_base.pl two our_reg.pm: two
second example:
Right,,in contrast to "our" the scope of "vars" is bound to "package". That's why one should use curlies around multiple packages, to clarify the scopes!!!
That's exactly my point, you can use "our" like "my", without getting confused about different scoping rules...
Cheers Rolf
UPDATES:
Let's sum it up, TIMTOWTDI, and you prefere saving code with the one variant and prefere saving some lines with the other .. ; )
well how is it done in perl6???
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^18: the "our" declaration ?!! (special vars)
by tilly (Archbishop) on Jan 22, 2009 at 14:58 UTC |