The following code:
will print the values ZYXABC. However I want to know if it is possible to reference the values in the anonymous array that is the key to the value anonymous array. I tried.#!/Perl/bin/perl use strict; use warnings; my %test = ('client' => {['11211','11111']=>['Z','Y','X'], ['10900','12345']=>['A','B','C']}); foreach my $key_a (keys(%test)) { foreach my $key_b (keys(%{$test{$key_a}})) { foreach my $i(@{$test{$key_a}{$key_b}}) { print $i."\n"; } } }
which yielded a symbolic reference error. Can anyone shed some light on my problem?#!/Perl/bin/perl use strict; use warnings; my %test = ('client' => {['11211','11111']=>['Z','Y','X'], ['10900','12345']=>['A','B','C']}); foreach my $key_a (keys(%test)) { foreach my $key_b (keys(%{$test{$key_a}})) { print $_ foreach @{$key_b} } }
I'm sure this is a no-no for good reason (making an anon array a hash key). Basically what I'm tryin to do is for a given client and a given data set, determine actions that should be taken on that dataset. So as to say for data pieces 11111 and 11211 I should do XYZ. So in lieu of listing them out as individual keys I thought that perhaps I could make them an array ref and only list the actions once. Someone guide me please because I'm kinda off I think.
edit Corion reminded me that only strings can be hash keys which explains the symbolic ref value.. since its simply storing the value "ARRAY0x000" rather than the actual ref. So in short.. problem solved.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |