in reply to Using a tied scalar as an in memory file
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using a tied scalar as an in memory file
by ikegami (Patriarch) on Feb 20, 2009 at 14:56 UTC | |
by ELISHEVA (Prior) on Feb 21, 2009 at 19:50 UTC | |
by ikegami (Patriarch) on Feb 21, 2009 at 21:05 UTC | |
by ELISHEVA (Prior) on Feb 22, 2009 at 13:12 UTC | |
by ikegami (Patriarch) on Feb 22, 2009 at 19:01 UTC | |
|
Re^2: Using a tied scalar as an in memory file
by duncs (Beadle) on Feb 20, 2009 at 09:24 UTC |