#!/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" }
In reply to Tie::Scalar::RandomInteger by Juerd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |