in reply to Re: Aliasing hash-element and scalar? (Not Solved Yet)
in thread Aliasing hash-element and scalar?

I'm not really sure that Perl syntax allows you to alias hash entry scalars, but you can achieve the effect by using Data::Alias:

use Data::Alias; use feature 'say'; $baz{'buf'} = 'Hello'; alias $foo{'bar'} = $baz{'buf'}; say $foo{'bar'}; $foo{'bar'} = 'World'; say $baz{'buf'}; $baz{'new'} = 'old'; say $foo{'old'}; __END__ Hello World Use of uninitialized value in say at ...

Replies are listed 'Best First'.
Re^3: Aliasing hash-element and scalar? (background)
by LanX (Saint) on Sep 03, 2018 at 19:27 UTC
    Thanks.

    Background: I was thinking to emulate the Python OO system, and in that language a class attribute can be accessed thru the same mechanism like an instance attribute.

    Hence assigning self.class_attr will change the value for all objects, assigning to self.obj_attr only to that specific object.

    Data::Alias seems like a good idea, unless Python has optional magic __hooks__ to intercept a get/set on class_attr.

    In that case I should rather use Tie::Scalar.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice