Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Dynamic Hash value

by mzedeler (Pilgrim)
on Apr 21, 2010 at 20:22 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-18 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found