#!/usr/bin/perl use strict; use warnings; package SillyClass2; sub new { my $class = shift; bless \@_, $class; } sub modifySubset: lvalue { my( $self, $start, $end ) = @_; @{ $self }[ $start .. $end ] ## Validate that all values in the slice being assigned are ## non-zero, even and uniq # my %uniq; # die 'Bad value' # unless $end - $start == grep{ # $_ && !( $_ & 1 ) && not ++$seen{ $_ } #} @{ $self }[ $start .. $end ]; } 1; package main; my $silly = SillyClass2->new( map $_ * 2, 1 .. 50 ); $silly->modifySubset( 15, 35 ) = ( 1 .. 20 ); ## should cause an error!