G
Gibbering
I want to access some data from a hash, but want to build that hash's
name on the fly... here's the code:
%hello = (a => 'doggy');
print ${'hell' . lc 'O'}{a};
does the trick as does:
print %{'hell' . lc 'O'}->{a};
however, under "use strict", this fails, since %hello isn't declared
with "my".
If I do put a my in front of the %hello declaration, the print
statement gives me nothing.
I have a sinking suspicion that the above code is wrong, dangerous,
and error prone since I'm not even sure why it works.
What is the proper way to do such a thing?
name on the fly... here's the code:
%hello = (a => 'doggy');
print ${'hell' . lc 'O'}{a};
does the trick as does:
print %{'hell' . lc 'O'}->{a};
however, under "use strict", this fails, since %hello isn't declared
with "my".
If I do put a my in front of the %hello declaration, the print
statement gives me nothing.
I have a sinking suspicion that the above code is wrong, dangerous,
and error prone since I'm not even sure why it works.
What is the proper way to do such a thing?