J
John
I'm taking apart somebody else's perl script in order to (a) learn and
(b) make something for my own purposes, and have come across a hash
that is not written in the manner to which I've become accustomed ...
the author is not within hollering distance, so I thought I'd try this
list for assistance.
Here's the hash as the author has created it:
$hashname{$key}{$other} = value;
where "$hashname" was initialized with "my %hashname", "$key" is a
scalar derived from input, and "$other" is another scalar also derived
from input.
It looks to me that "other" is outside of the key and obviously isn't
the value either. The script I found it in works as the author
intended, so the structure is obviously legal, but I don't understand
it. I was under the impression that a hash in scalar context should
look like:
$hashname{$key} = value;
or
%hashname(key => value);
or
%hashname("key","value");
but not
%hashname{$key}{$other} = value;
I thought maybe it was intended to be some kind of index notation, but
the actual value of that var is a string and not a digit, and if it
was supposed to be a reference of some sort to make or indicate the
key is another array (hash of hashes?), then I would expect the var
"$other" to be inside the key's curly braces, not outside in their own
braces (i.e. "$hashname{$key{$other}} = value;" as opposed to
"$hashname{$key}{$other} = value.
Can somebody enlighten me on what that {$other} is all about? How
does it work? Why does it work?
best regards,
John
(b) make something for my own purposes, and have come across a hash
that is not written in the manner to which I've become accustomed ...
the author is not within hollering distance, so I thought I'd try this
list for assistance.
Here's the hash as the author has created it:
$hashname{$key}{$other} = value;
where "$hashname" was initialized with "my %hashname", "$key" is a
scalar derived from input, and "$other" is another scalar also derived
from input.
It looks to me that "other" is outside of the key and obviously isn't
the value either. The script I found it in works as the author
intended, so the structure is obviously legal, but I don't understand
it. I was under the impression that a hash in scalar context should
look like:
$hashname{$key} = value;
or
%hashname(key => value);
or
%hashname("key","value");
but not
%hashname{$key}{$other} = value;
I thought maybe it was intended to be some kind of index notation, but
the actual value of that var is a string and not a digit, and if it
was supposed to be a reference of some sort to make or indicate the
key is another array (hash of hashes?), then I would expect the var
"$other" to be inside the key's curly braces, not outside in their own
braces (i.e. "$hashname{$key{$other}} = value;" as opposed to
"$hashname{$key}{$other} = value.
Can somebody enlighten me on what that {$other} is all about? How
does it work? Why does it work?
best regards,
John