in reply to A Tied hash returning a tied scalar which becomes untied, why?

Tied variables cannot be returned.

sub mysub { tie my $tied, 'MyClass'; return $tied; # Calls FETCH and returns } # the fetched value. my $not_tied = mysub();

Similarly, tied variables cannot be assigned.

tie my $tied, 'MyClass'; my $not_tied = $tied; # Calls FETCH and assigns # the fetched value.

However, there's no special limitation on references to tied variables.

sub mysub { tie my $tied, 'MyClass'; return \$tied; # Returns a ref to the tied var. my $ref_to_tied1 = mysub(); my $ref_to_tied2 = $ref_to_tied; print($$ref_to_tied1, "\n"); # Calls $tied's FETCH. print($$ref_to_tied2, "\n"); # Calls $tied's FETCH.