in reply to subroutine / dot operator / hash vlaue
Output:#!/usr/bin/env perl use strict; use warnings; use 5.010; my $hash = { key => ' value1 '.get_value2()}; say $hash->{key}; say $hash->{key}; say $hash->{key}; $hash = { key => ' value2 '.get_value2()}; say $hash->{key}; say $hash->{key}; say $hash->{key}; sub get_value2 { return rand(); }
Every time my get_value2 is called, it will return a different random number, but you can see in the output that the value printed changed only when I re-set the hash, not each time the hash was accessed.value1 0.557144237523065 value1 0.557144237523065 value1 0.557144237523065 value2 0.0543176085661514 value2 0.0543176085661514 value2 0.0543176085661514
But I agree that this smells like an XY Problem. What are you actually trying to accomplish (or what bug are you actually attempting to identify) here?
|
|---|