O'Reilly logo

Perl Medic: Transforming Legacy Code by Peter Scott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix: Source Code

Tie::Array::Bounded

package Tie::Array::Bounded;use strict;use warnings;use Carp;use base qw(Tie::Array);our $VERSION = '0.01';sub TIEARRAY{  my ($class, %arg) = @_;  my ($upper, $lower) = delete @arg{qw(upper lower)};  croak "Illegal arguments in tie" if %arg;  $lower ||= 0;  croak "No upper bound for array" unless $upper;  /\D/ and croak "Array bound must be integer"    for ($upper, $lower);  croak "Upper bound < lower bound" if $upper < $lower;  return bless { upper => $upper,                 lower => $lower,                 array => []               }, $class;}sub _bound_check{  my ($self, $index) = @_;  my ($upper, $lower) = @{$self}{qw(upper lower)};  croak "Index $index out of range ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required