And there is yet a third problem with tied scalars. When scalars are passed to a function, e.g. open they are copied (not passed by reference).
Ties do not propagate after a copy, hence the scalar, but neither the tied object nor its associated sub are being passed. The reason you are seeing the correct thing when you print is that when a tied variable is copied, whatever is returned by FETCH is assigned to the variable on the left. Last night I had the similar problem as you when I tried to pass a tied variable to die - which also strips the tied portion from the scalar and throws only the value returned by FETCH
To quote from Programming Perl:
The tie is on the variable, not the value, so the tied nature of a variable does not propagate across assignment. For example, let's say you copy a variable that's been tied:
$dromedary = $camel;Instead of reading the value in the ordinary fashion from the $camel scalar variable, Perl invokes the FETCH method on the associated underlying object. It's as though you'd written this:
$dromedary = (tied $camel)->FETCH():
Best, beth
In reply to Re: Using a tied scalar as an in memory file
by ELISHEVA
in thread Using a tied scalar as an in memory file
by duncs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |