Ok...incrementing by 0.5 works.
But the plot thickens...it "only" works with ActiveState...incrementing by 1
(as below) works on Linux. Hmmm.
Eric
> -----Original Message-----
> From: Kort, Eric [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 20, 2001 12:36 PM
> To: [EMAIL PROTECTED]
> Subject: Incrementing by one
>
>
> Damian Conway's book OO Perl, in discussing ties, suggests that the
> following will create a scalar that increments by one
> everytime its value is
> accessed:
>
> package Incr;
>
> sub TIESCALAR
> {
> my ($class) = @_;
> my $value = 0;
> bless \$value, $class;
> }
>
> sub FETCH
> {
> my ($value) = @_;
> return ++${$value};
> }
>
> But, when I do the following:
>
> #!perl
>
> use lib "C:\\Perl";
> use Incr;
>
> tie $foo, "Incr";
> print "$foo\n";
> print "$foo\n";
> print "$foo\n";
> print "$foo\n";
> print "$foo\n";
>
> exit;
>
> I get:
> 2
> 4
> 6
> 8
> 10
>
> Presumable because FETCH calls FETCH itself to do the incrementing,
> resulting in a double increment! How can one get a single
> increment with a
> tie?
>