Hi
I have an hash as $Hash{Name}{NickName}
Where Name is String
NickName Array
I can get All NickName in an array as
@AllNN=values @{$$Hash{Name}}
my query is Why I cant get the same result with
@AllNN=values %{$Hash{Name}}
or
@AllNN=values $Hash{Name}
Analize your datastructure. It looks something like this, yes?
%Hash = (
'Robert' => ['Bob', 'Rob'],
'William' => ['Will', 'Billy'],
);
Now analize the code you were trying to use.
values %{$Hash{'Robert'}}
$Hash{'Robert'} is an array reference. It references an array
containing Bob and Rob. You cannot derefernce this as a hash because
it is not a hash reference.
values $Hash{'Robert'}
$Hash{'Robert'} is an array reference. You cannot use values on an
array reference. The argument to values() must be a hash.
I don't quite understand your claim that values @{$$Hash{Name}} works
like you want it. Even if I have misunderstood your datastructure,
you cannot pass an array to values(). This is a syntax error.
Using the datastructure I typed above, you would get all the
nicknames for a particular name like this:
@nicks = @{$Hash{'Robert'}};
If you want all nicknames, you could use something like this:
@all_nicks = map { @{$Hash{$_}} } keys %Hash;
If you need further assistance (if, for example, I have not understood
your description of your datastructure), please post a short but
complete program demonstrating your issue.
Thank you,
Paul Lalli