Variable binding several times

Is it possible to bind a variable several times? I would try this myself, but I'm not sure about the syntax. I want to bind the hash to Cache :: Memcached :: Tie and IPC :: Shareable .

+4
source share
3 answers

I do not think that it is possible to bind two classes to one element. After completing the tie a second time, simply delete the original link and replace it with a new one.

It should be possible to write some sort of multi-submission. I mean writing a class that accepts several other classes, and calling their corresponding methods, such as FETCH or STORE .

+1
source

No. Confirming the bvr assumption, a variable can have only one β€œbound” magic. When you call tie on an already bound variable, the existing arcane magic (and the associated bound object) is discarded until a new binding is created.

Toy example:

 package Foo; sub TIESCALAR { return bless [] } sub DESTROY { print "Destroying Foo\n" } package Bar; sub TIESCALAR { return bless [] } sub DESTROY { print "Destroying Bar\n" } package main; tie my $var, "Foo"; print "Tied to ", ref tied $var, "\n"; tie $var, "Bar"; print "Tied to ", ref tied $var, "\n"; 

Output:

 Tied to Foo Destroying Foo Tied to Bar Destroying Bar 
+6
source

Not only is this impossible, but not reasonable. What does choice mean in this context? How to handle them, returning two different values?

What I suspect you want is a multi-level caching system, you might want to look into CHI .

+4
source

Source: https://habr.com/ru/post/1368963/


All Articles