If your data is always going to be a HoHoH..., I would write a little function that plucks your attributes out for you, and saves you the tedious typing in your code. The function would accept a path to the value you're seeking in dotted-path notation. Something like this:
use strict; use warnings; # Recursive function to traverse a HoH according to a # "dotted" properties path: sub getprop{ my ($properties, $path) = @_; return $properties unless $path; my ($key, @remaining_path) = split /\./, $path; return getprop($properties->{$key}, join('.' => @remaining_path)); } # Define our properties: my $mylovelydata= { 'Colour'=>'blue', 'Entries'=> { 'Flowers'=> { 'Dahlia'=>{'Smell'=>'nice',}, 'Rose'=>{'Colour'=>'red'}, } }, }; # Test the function for my $flower qw/Dahlia Rose/{ my $colour = getprop($mylovelydata, "Entries.Flowers.$flower.Colou +r"); $colour = getprop($mylovelydata, "Entries.Colour") unless defined( +$colour); $colour = getprop($mylovelydata, "Colour") unless defined($colour) +; print "A ${flower}'s color is: $colour\n"; } __END__ A Dahlia's color is: blue A Rose's color is: red
This allows for less typing, but more importantly, I think, it just looks a lot cleaner. You could even expand the getprop function to handle accessing arrays stashed in your properties data structure with something like Some.Array[1].Property.

Update:: This idea is actually stolen from JavaScript. It allows you to "walk" a data structure in a similar fashion. For instance, to access a hidden field named "somedata" in the second form of a web page, you'd write something like var value = document.forms[1].somedata.

In reply to Re: Inheritance in Hash by crashtest
in thread Inheritance in Hash by Eyck

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.