Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Another version, using a tied hash:

#!/usr/bin/perl package DynHash; use Tie::Hash; our @ISA = 'Tie::StdHash'; sub TIEHASH { my $class = shift; return bless {}, $class; } sub FETCH { my $self = shift; return ${ $self->{$_[0]}[0] } - ${ $self->{$_[0]}[1] } } package main; use Data::Dumper; tie my %result, "DynHash"; my $ini = 4; my $last = 2; %result = ( SAS1 => [ \$ini, \$last ], SAS2 => [ \$last, \$ini ], SAS3 => [ \$ini, \$last ] ); print Dumper \%result; $ini = 10; $last = 5; print Dumper \%result; __END__ $VAR1 = { 'SAS3' => 2, 'SAS2' => -2, 'SAS1' => 2 }; $VAR1 = { 'SAS3' => 5, 'SAS2' => -5, 'SAS1' => 5 };

i.e., store references to $ini and $last in the hash, and dynamically recompute the difference from them at the time the values of the (tied) hash are being fetched.

In reply to Re: Dynamic Hash value by almut
in thread Dynamic Hash value by Bheema_Tyco

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2023-09-28 18:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found