in reply to Re^4: Qualified package variable access ( private methods )
in thread Qualified package variable access
Well, one major difference is that that $private is not a member of the class at all, it is a lexical in the same block in which you've defined the subs of the class. And, of course, it's singleton. A class private in C++/Java is not singleton. It could be declared 'static', which would make it singleton; but that still wouldn't be the same as what you've shown. If your $private were truly equivalent, you'd be able to write this:
use strict; use warnings; { package Class; my $n = 42; sub new { my $pkg = shift; bless {}, $pkg; } sub foo; } sub Class::foo { print "$n\n"; }
But you can't, of course, because $n is out of scope at that point. It is not a member of the "class".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Qualified package variable access ( private methods )
by LanX (Saint) on Dec 21, 2020 at 20:36 UTC |