Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Dynamic Hash value

by Bheema_Tyco (Novice)
on Apr 21, 2010 at 08:45 UTC ( [id://835995]=note: print w/replies, xml ) Need Help??


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

Actually Like SAS1, SAS2, SAS3, ...etc are there. Based on those value i am calculating the value say $some_value.

which($some_value) may either $ini-$last or $last-$ini

So for that i am building hash %result with SAS1, SAS2., SAS.. as key and either $ini-$last or $last-$ini as value

So later in the code if i change the values of either $ini or $last then this changed value should reflect in the hash such that whenever i retrieved hash value using SASx as key then it should give the latest result

.

If You wants to suggest something like Tie:Scalar please bit elaborate on Tie:Scalar thing as i dont know about that

Because somebody has suggested that. But i didn't get that. I found Corion's example is good actually

Please help me

Thanks

Replies are listed 'Best First'.
Re^3: Dynamic Hash value
by mzedeler (Pilgrim) on Apr 21, 2010 at 20:22 UTC

    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.

Re^3: Dynamic Hash value
by LanX (Saint) on Apr 21, 2010 at 08:59 UTC
    > If You wants to suggest something like Tie:Scalar please bit elaborate on Tie:Scalar thing as i dont know about that

    Because somebody has suggested that. But i didn't get that.

    I suggested others already "elaborated", but it seems you didn't read ...

    Paṛha kr̥payā!

    > I found Corion's example is good actually
    >
    > Please help me

    My helpful advice: Use Corions example!

    > Thanks

    Your welcome! 8)

    Cheers Rolf

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-28 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found