Have a look at the very useful References quick reference.

Also, the keys doc. The argument for keys must be a hash and has a % sigil.

for my $key (keys %hash){ #... } for my $key (keys %{$hashref}){ # dereferencing a hash #... }
The exists doc tells you its argument is a hash element which will have a $ sigil. You need to read your error message
exists argument is not a HASH or ARRAY element
as
exists argument is neither a HASH element nor an ARRAY element
if (exists $hash{some_key}){ #.. } if (exists $hashref->{some_key}){ # dereferencing a hash element using + an arrow #.. }
An observation.
...what about %{$$coordinates{$group}{$id}{$stage}{"coords"}}...
The %{...} does the dereferencing, there's no need for the extra $ in $$. I prefer the -> for dereferencing (many monks don't) but it is often unnecessary (as in this case).

Have a look at the tutorial linked to above. I look at it at least once a week. :-)

update: When I'm have a fight with a convoluted data structure I try out the syntax on a simplified version and get that working first. And while you're doing that don't forget the mighty Data::Dumper. Good luck!


In reply to Re^2: Test if a subhash in a referenced hash exists by wfsp
in thread Test if a subhash in a referenced hash exists by Henri

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.