in reply to call subroutine if scalar is changed

tie is overkill. Use Variable::Magic.

use Variable::Magic qw( wizard cast ); my $wiz = wizard( set => sub { print "Now set to ${$_[0]}.\n" }, ); cast my $name, $wiz;

Replies are listed 'Best First'.
Re^2: call subroutine if scalar is changed
by stevieb (Canon) on Jun 09, 2019 at 00:09 UTC

    Now that is interesting.

    Thanks for a new rabbit hole that I didn't have time for :)

Re^2: call subroutine if scalar is changed
by LanX (Saint) on Jul 26, 2019 at 23:44 UTC
    I suppose this could be used to couple two variables @a=@$a or vice versa $a=@$a such that the coupling survives new assignments and the partner is destroyed as soon as the original is? 🤩

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

      Yes, though I think it would be easier with tie.