If $myvariable is a package variable, you might find what you want by looking into the symbol table of caller. So technically you could do it, but that looks like a very bad idea.
What you should actually do, is use the fact that tie can take more than two arguments. Any argument after the class will be forwarded to the tying method. You would just have to call:
tie($myvariable, "MyObject", 'A name');.
You could even make a sub that calls tie for you, after you gave it the variable name and class :
I'm not sure about that last one though, about tying a variable into the scope of an eval, even though I can't see why that wouldn't work.sub mytie { ($name, $class) = @_; eval "tie $name, '$class', '$name';"; # UPG: I forgot the third para +meter }
Upgrade: corrected the mytie example which was useless.
In reply to Re: Accessing name of tied variable in tie constructor
by Eily
in thread Accessing name of tied variable in tie constructor
by djcp3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |