in reply to Re^2: Dynamic Hash value
in thread Dynamic Hash value

It is a most unusual way to solve this kind of selection problems by using references. You get into the dreaded Action at A Distance anti-pattern by doing so. It is much more obvious to just write a function:

my $last = 0; my $ini = 0; ... $last = <something else>; ... $ini = <something else>; ... # now you need $some_value: my $selector = 'SAS1'; my $some_value = compute_sas($selector, $ini, $last); sub compute_sas { my($selector, $ini, $last) = @_; if($selector eq 'SAS1') { return $ini - $last; } else { return $last - $ini; } }

Note that the sub compute_sas is sloppy, untested and probably not giving the right results, but it should illustrate my point.