One idea comes immediately to mind, and that's to use references.

A reference is basically a pointer; you use it to point to the data you're working with, and then dereference it to assign or read its current value.

So, for example, with phash being the reference (pointer) to your hash:

my $phash = \%Tech_fy_reldata; # Assign to hash reference (eg. \%hash +) while(<NEW>){ @val=split /\t/; foreach my $val (@val) { my $pvalue = $phash; # Start with reference to hash if (CONDITION1) { $pvalue = $pvalue->{KEY1}; # Down 1 level if (CONDITION2) { $pvalue = $pvalue->{KEY2}; # Down another level # ... etc ... } } $$pvalue = VALUE; # Use $$ to dereference for assignment } }
In the above code, CONDITION1, CONDITION2, etc. are the conditions you've chosen to descend another level in the hash, and KEY1, KEY2, etc. are the corresponding keys at each lower level.  So, in your original example, if the keys were $val[$npo] and $val[$fy_closed], then when you got to the line:
$$pvalue = VALUE; # Use $$ to dereference for assignment

$pvalue would be pointing to $Tech_fy_reldata{$val[$npo]}{$val[$fy_closed]}, and the assignment is made by dereferencing the pointer with $$pvalue.  Each time through the loop, the pointer pvalue gets reinitialized to the top-level hash pointer.

Try reading perlref and/or perlreftut if you'd like more information on references.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Re: Generating HoH... by liverpole
in thread Generating HoH... by Anonymous Monk

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.