Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Dynamic Hash value

by mzedeler (Pilgrim)
on Apr 21, 2010 at 20:22 UTC ( #836121=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://836121]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2023-10-04 14:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found