A stupid little script that ties a scalar. I wrote it to show someone how tie works.

Update (200201021139+0100)
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" }

Replies are listed 'Best First'.
Re: Tie::RandomInteger
by Juerd (Abbot) on Dec 29, 2001 at 19:55 UTC
    Someone just told me that "dice" is "die"'s plural. Sorry about that :)

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$