A stupid little script that ties a scalar. I wrote it to show someone how
tie works.
Update (200201021139+0100)
- Changed the name to Tie::Scalar::RandomInteger (old: Tie::RandomInteger) to tie-dy up our namespaces
- $min + int rand $max was stupid. Why didn't anyone see this? Should have been $min + int rand ($max - $min) of course.
Update (200201100047+0100
- blakem found two mistakes. I forgot an arrow, and forgot to change
the package name in the test script;
#!/usr/bin/perl -w
package Tie::Scalar::RandomInteger;
use strict;
sub TIESCALAR {
my ($class, $min, $max) = @_;
return bless [ $min, $max ], $class;
}
sub FETCH {
my ($self) = @_;
return $self->[0] + int rand ($self->[1] - $self->[0]);
}
sub STORE { undef }
sub UNTIE { undef }
sub DESTROY { undef }
package main;
use strict;
tie my $dice, 'Tie::Scalar::RandomInteger', 1, 6;
ROLLDICE:
for (1..10){
print "$dice\n"
}