Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: call subroutine if scalar is changed

by ikegami (Patriarch)
on Jun 08, 2019 at 23:56 UTC ( [id://11101148]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11101148]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-18 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found