in reply to how to alias a subset of an array
You can't have it like that. You might be able to have it like this (see perltie if you want array syntax)
But that seems kludgey and doesn't save any memory for simple numbers.@A = (1,2,3,4,5,7,21,55,66); $B = RangeRestriction( \@A, [2..4] ); warn $B->(0) ; warn $A[2] ; warn $B->(0) == $A[2] ; sub RangeRestriction { my ( $array, $range ) = @_; return sub { my($index) = @_; $index = $range->[ $index ]; return $array->[ $index ]; }; } __END__ 3 at - line 3. 3 at - line 4. 1 at - line 5.
|
|---|