in reply to Delay evaluation of tied scalar when returned from sub

Just a thought. If it really is the print statement when you need the call, then maybe you could use overload:
use overload  ('""' => 'RealFetch');
?

Replies are listed 'Best First'.
Re^2: Delay evaluation of tied scalar when returned from sub
by harryf (Beadle) on Aug 30, 2006 at 12:10 UTC
    Interesting. I guess overload could take me some of the way there but it won't just be print; or I don't know how the value may end up being used - might be something like;
    my $percentUsersOnline = ($usersOnline / $numUsers) * 100;
    At which point the value needs evaluating. Haven't played with overload knowingly before but get the feeling it's likely to end up as a messy hack - that the variable gets used in some way I hadn't predicted, and fails to be evaluated. Gets me thinking though - wonder if there's some way by looking the call stack via caller?