in reply to Re^2: How to access globals in arbitrary classes, without using soft ref?
in thread How to access globals in arbitrary classes, without using soft ref?

They are called symbolic refs.

I must disagree with moritz. Using %:: instead of symbolic refs does not help at all. All the same problems and disadvantages exist because it does exactly the same thing. Using %:: has the additional disadvantage that it's not caught by use strict 'refs';. In fact, it's generally less readable and harder to code using %:: instead of symbolic refs, so it's usually a step backwards to use %::.

If you want to improve your approach, use accessors.

use strict; { package Foo; my $str = 'foo str'; sub str { my $class = shift; $str = $_[0] if @_; return $str; } } { package Bar; my $str = 'bar str'; sub str { my $class = shift; $str = $_[0] if @_; return $str; } } my $class = 'Foo'; my $value = $class->str();