To answer my own question: Yes!
use strict; use warnings; use 5.10.0; package Tie::Alias; require Tie::Scalar; our @ISA = qw(Tie::Scalar); use Data::Dump qw/pp dd/; sub FETCH { #pp \@_; my $obj =shift; return ${$obj->{alias}}; } sub STORE { #pp \@_; my $obj = shift; ${$obj->{alias}} = $_[0]; } sub TIESCALAR { #pp \@_; my $class = shift; my $alias = \ shift; my $obj = bless {alias => $alias}, $class; return $obj; } package main; my $h={}; my $y; tie $h->{y},'Tie::Alias', $y; $y=666; say $h->{y}; $y=42; say $h->{y}; $h->{y}=123; say $y; my $g={}; tie $g->{y},'Tie::Alias', $y; say $g->{y}; $h->{y}=999; say "$h->{y},$g->{y},$y"; $h->{x}="whatever"; say "$h->{x},$g->{x}";
Use of uninitialized value in concatenation (.) or string at d:/Users/ +lanx/exp/tie_alias.pl line 72. 666 42 123 123 999,999,999 whatever,
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
In reply to Re: Aliasing hash-element and scalar? (Tie::Scalar)
by LanX
in thread Aliasing hash-element and scalar?
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |