|Perl Monk, Perl Meditation|
Re: How might I return tied scalar that does not have to be dereferenced as $$scalar?by dada (Chaplain)
|on Sep 20, 2002 at 12:12 UTC||Need Help??|
this isn't completely possible. no matter what you do with tie, bless, etc. the following lines won't work as you expect:
with a tie, you can't directly do $d->to_unixtime, it has to be tied($d)->to_unixtime. otherwise you'll get the message: Can't locate object method "to_unixtime" via package "Nov 25, 1971" (perhaps you forgot to load "Nov 25, 1971"?)
with a regular object, you can't of course do $d = "Nov 25, 1971" because this would destroy the object previously assigned to $d.
the most functional hack I could come up with is the use of tie AND overload AND tye's suggestion, as in:
this prints what you expect:
...but this is a hack, as it works correctly only when fetching $d in a string context. it has the implicit advantage, however, that $d could return something different (perhaps $d->to_unixtime) in numeric context.
King of Laziness, Wizard of Impatience, Lord of Hubris