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:
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: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 } }
$$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.
In reply to Re: Generating HoH...
by liverpole
in thread Generating HoH...
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |