in first case, when exactly perl runs subroutine? does it runs get_vlaue2() every time we try to access $hash->{key}?You can use a few print statements to find this out:
print "Start\n"; my $hash = { key => 'value1' . get_value() }; print "hash created\n"; print "accessing hash key\n"; my $key = $hash->{'key'}; print "hash key is '$key'\n"; print "Finish\n"; sub get_value { print "get_value() called\n"; return "value"; }
In reply to Re: subroutine / dot operator / hash vlaue
by tangent
in thread subroutine / dot operator / hash vlaue
by starfire4444
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |