As for your first question of how to reduce the amount of typing, it very much depends on what you want to do with your structure. If you're populating it, you probably have some simpler structures that contain the data being entered into the 3-level hash. Loop through them. Or if you're manually adding each elemnt, you're somewhat stuck.
For the second part, in relation to your readItem() function, and assigning to the structure, you have multiple problems. First off, you should pass you structure in to the function, instead of using it as a global, i.e.:
... # populate your %project readItem(\%project); ... sub readItem { my ($project) = @_; my $sub_project = $project->{...}->{...}; etc. }
If that doesn't make sense, you need to read more about variable scope.
As for assigning into a referenced subpart, the important thing to consider is what just got deferenced when you created the sub part. Is it a hashref thats also pointed to by your big structure, or is it a scalar, or is it a newly created anonymous structure?
my %multi_level = ( 'foo' => { 1 => 'A', 2 => 'B' }, 'bar' => { 'C' => 'see', 'T' => 'tea' }, ); my $sub_part = $multi_level{foo}; # sub_part is a hashref, # also pointed at by $multi_level{foo} print $multi_level{foo}->{1} . "\n"; # works (prints 'A') $sub_part->{3} = 'C'; print $multi_level{foo}->{3} . "\n"; # works (prints 'C') my $part_two = $multi_level{foo}->{1}; # part_two is a # scalar, a copy of the value of $multi_level{foo}->{1}, # namely 'A'. Changing it will not change %multi_level
the $part_two example may make more sense if you think of this:
my $a = 'blah'; my $b = $a; $b = 'foo'; print "$a\n"; # prints 'blah' print "$b\n"; # prints 'foo'

I use the most powerful debugger available: print!

In reply to Re: Using multi-level hashes by shemp
in thread Using multi-level hashes by carcassonne

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.