Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: symboltable problem

by morgon (Curate)
on Jun 20, 2012 at 19:22 UTC ( #977452=note: print w/replies, xml ) Need Help??

in reply to Re: symboltable problem
in thread symboltable problem

Ok, call me stupid but I don't get what you are trying to say.

I re-phrase my question:

For package "Hubba", it's symbol table is stored in a hash %Hubba:: that maps symbol-names to typeglobs.

So when I do %Bubba:: = %Hubba:: (I am NOT doing *Bubba::=*Hubba::) the whole symbol-to-typeglob mapping is copied to another hash (which happens to be the symbol-table of another package).

So why does that then not create aliases?

I can do this:

our $var = "zappa"; $Bubba::{abba} = *var; print $Bubba::abba;
which shows that I can create variables by manipulating the symbol-table. Why does that not happen in my script?

Can someone explain that in plain english without using the word "magic"?

Replies are listed 'Best First'.
Re^3: symboltable problem
by Eliya (Vicar) on Jun 20, 2012 at 21:26 UTC

    I think the problem is that %Bubba:: = %Hubba:: is creating a new hash, which destroys the binding of $Bubba::abba to the original hash set up at compile time of the latter expression.  This reasoning is based on the observation that both of the following work fine:

    #!/usr/bin/perl use strict; $Hubba::abba = "zappa\n"; %Bubba:: = %Hubba::; # compile time deferred eval 'print $Bubba::abba';
    #!/usr/bin/perl use strict; $Hubba::abba = "zappa\n"; # copying via hash slice doesn't create new hash @Bubba::{keys %Hubba::} = @Hubba::{keys %Hubba::}; # or: @Bubba::{keys %Hubba::} = values %Hubba::; print $Bubba::abba;
      Yes, that seems to eplain it. Another solution then is to create the alias in a BEGIN block.
      Thanks - that is very interesting. I did not expect that...

      I find this illustration quite amusing:

      use strict; our $foo = "old value\n"; %:: = (%::); our $var = "new value\n"; $::{foo} = *var; print $foo; eval q| print $foo |;
      btw: Is there a nicer way to create a typeglob with a given value in the scalar-slot?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://977452]
[marto]: it does literally nothing, solves no problems that aren't already addressed, but it's real easy to mine, because nobody is doing it
[LanX]: is producing broken links for me ...
erix foresees fungibility problems ;)
erix goes afk - catch y'all later
[Corion]: LanX: Broken links in what sense?
[Discipulus]: neurocent goes always up with the same curve of population raise
[marto]: believe in derp coin
[Corion]: Oh - I see ...
[LanX]: like http://cb60. 1215217
[Discipulus]: username links i bet

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-05-25 15:56 GMT
Find Nodes?
    Voting Booth?