Sets the removal policy for an ordered hash. The removal policy is called when a new value is added to the hash. The return value of the policy determines wether the last element in the hash should be removed or not.
%ohash - the ordered hash to set the miss policy for
&closure - the miss policy closure.
When called, the closure receives the following arguments:
Argument Description $1 the ordered hash scalar $2 the key of the last element in the hash (the removal candidate) $3 the value of the last element in the hash
sub policy { if (size($1) >= 3) { println("Removing key: $2 value: $3"); return 1; } return 0; } %cache = ohasha(a => "apple", b => "bat", c => "cat"); setRemovalPolicy(%cache, &policy); println(%cache); println("Access 'a': " . %cache["a"]); println(%cache); %cache["d"] = "dog"; println(%cache);
%(a => 'apple', b => 'bat', c => 'cat') Access 'a': apple %(b => 'bat', c => 'cat', a => 'apple') Removing key: b value: bat %(c => 'cat', a => 'apple', d => 'dog')