> Q2. can I Tie::Scalar only a single element of a hash?

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.