Monestarians

The following code:

#!/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"; } } }
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}})) { print $_ foreach @{$key_b} } }
which yielded a symbolic reference error. Can anyone shed some light on my problem?

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.


Grygonos

In reply to HoHoA with anonymous array refs as the key to access the A by Grygonos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.