smitz has asked for the wisdom of the Perl Monks concerning the following question:

Ok, just been teaching myself about tie, and thought I was getting the hang of it, so I built myself two things:

1. Stopwatch.pm
This module has, surprisingly, four methods. No prizes for guessing what they're called!
Now then, each sub in Stopwatch contains a print statement along the lines of: print ("Inside Stopwatch::TIESCALAR"); so I know which sub is being executed.

2. go.pl, in its entirety, is here:
use Stopwatch; print "Just executed use\n"; tie $s, 'Stopwatch'; print "Just executed tie\n"; $s = 0; print "Just executed \$s = 0;\n"; print "$s\n"; print "Just executed print \$s\n"; $s = undef; print "Just executed undef\n";
So what? I hear you cry...
Well, all's well untill the print "$s\n"; statement. It calls Stopwatch::FETCH twice in a row. Why??? For some reason this small 'feature' is really getting under my skin, any explanations very welcome!


advTHANKSvance,
SMiTZ

Replies are listed 'Best First'.
Re: Tie's FETCH called twice?
by blakem (Monsignor) on Oct 28, 2001 at 20:35 UTC
    This is a bug that has been noted elsewhere but to my knowledge there is no known patch or workaround....

    -Blake

      No, a closer read would reveal this one does have a workaround, simply not using the value as the first part of a concatenation.
      print "$tie\n"; #Double fetch print "Tiesvalue:$tie\n"; #single fetch
      :->

      Yves / DeMerphq
      --
      Have you registered your Name Space?

      Update
      crazyinsomniac pointed out that I put /n instead of \n into my examples. My bad, but fixed now.. Thanx dude.

        Ahh, hmmm...so...
        Ok, your obviously right, that does work, but how come? Wht is the 1st a double fetch? Is that the bug, or is it my mistake? If it is the latter, could someone explain it? Thanx again! SMiTZ