Tie::Subset::Array - Tie an array to a subset of another array
use Tie::Subset::Array; my @array = (55,66,77,88,99); tie my @subset, 'Tie::Subset::Array', \@array, [1,2,3]; print "$subset\n"; # prints "77" $subset++; # modifies $array
This class for tied arrays provides a "view" of a subset of an array.
tie my @subset, 'Tie::Subset::Array', \@array, \@indices;
You must specify which subset of indices from the original array should be part of the new array. (Indices that do not yet exist in the original hash may be specified.) The subset (tied array) will be the same size as
@indices, and is indexed by the usual 0 to
If the index is within the bounds of the tied array, the value from the underlying array is returned, otherwise returns nothing (undef).
If the index is within the bounds of the tied array, the new value will be stored in the underlying array, otherwise the operation is ignored and a warning issued.
Note: The Perl documentation strongly discourages from calling exists on array values.
Will return true only if the index
existsin the subset and the corresponding index in the underlying array
- Not Supported
Any operations that modify the size of the tied array are not (yet) supported (because it is ambiguous how such operations should affect the underlying array). Attempting to change the tied array's size, including using
splice, assigning to the
$#arraynotation, clearing the array, etc. will currently do nothing and cause a warning to be issued, and operations that normally return a value will return nothing.
The above is also true for attempting to
deletearray elements, which the Perl documentation strongly discourages anyway.
A future version of this module may lift these limitations (if a useful default behavior exists).
Copyright (c) 2018 Hauke Daempfling (firstname.lastname@example.org).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.